@ECHO OFF
TITLE Install/Uninstall Remote Administrator to \\%1
SETLOCAL enabledelayedexpansion
SET comp=%1
CD /d "%~dp0"

DIR "\\%comp%\c$\Program Files\" > nul 2<&1
IF ERRORLEVEL 1 (
	rem Run this file as Administrator
	RUNAS /netonly /noprofile /env /user:Administrator "cmd /k %~s0 %1"
	IF ERRORLEVEL 1 PAUSE
	EXIT
)

SET RAdir=\\%comp%\c$\Program Files\RAdmin

IF EXIST "!RAdir!\r_server.exe" (
	rem Uninstall
	TITLE Uninstall Remote Administrator to \\%1
	SET /P =Uninstall Remote Administrator? [Press Enter to continue]: 
	..\PsExec.exe \\%comp% "c:\Program Files\RAdmin\r_server.exe" /uninstall /silence
	RD /q /s "!RAdir!"
) ELSE (
	rem Install
	TITLE Install Remote Administrator to \\%1
	SET /P =Install Remote Administrator? [Press Enter to continue]: 
	XCOPY r_server.exe "!RAdir!\" /Y
	XCOPY admdll.dll "!RAdir!\" /Y
	XCOPY raddrv.dll "!RAdir!\" /Y
	..\PsExec.exe \\%comp% "c:\Program Files\RAdmin\r_server.exe" /save /silence
	..\PsExec.exe \\%comp% "c:\Program Files\RAdmin\r_server.exe" /install /silence
	SC \\%comp% start "r_server"
)

PAUSE
