Saturday, October 3, 2009

BAT - Enable Remote Desktop on Remote Computer

Tested on XP, Vista, Windows 7, Windows Server 2003 and Windows Server 2008.

@echo off
if %1=="" (
    goto USAGE
) else (
    goto VERIFY
)

:USAGE
echo ***************************************
echo Usage:
echo enable_remote_desktop.bat [computername]
echo .
echo ***************************************
goto END

:VERIFY
if EXIST \\%1\c$\windows\system32 (
    goto ENABLE
) else (
    goto OFFLINE
)

:OFFLINE
echo ***************************************
echo %1 is not accessible
echo check the name and try again or ensure
echo the client is online and firewall is
echo not preventing access
echo ***************************************
goto END

:ENABLE
echo Configuring registry setting on %1...
REG ADD \\%1\HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server /v fDenyTSConnections /t REG_DWORD /d 0 /f
rem goto REBOOT
echo %1 has been configured
goto END

:REBOOT
echo Requesting a restart of %1...
shutdown -m \\%1 -r -f -t 5
echo Request submitted.  Please allow a few minutes before
echo attempting to connect via remote desktop.
goto END

:END

No comments:

Post a Comment