Hey I forgot to turn on RDP on my server!

Ever find yourself away from your server after building it out and forgot to turn on RDP so you could TS onto the machine?  Well in XP and 2k3, you can just toggle a reg key and most of the time (pending firewall issues) you can then TS into the box.  Doesn't work in Windows 2000 as you need to install a service for TS, which is why the script checks that below.

Here's an easy script that you can save as a cmd file that will work...

@echo off

IF "%1"=="?" GOTO SYNTAX
IF "%1"=="/?" GOTO SYNTAX
IF "%1"=="-?" GOTO SYNTAX

reg query "\\%1\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion" /v CurrentBuildNumber |findstr CurrentBuildNumber >> c:\tmp.txt
for /f "tokens=3" %%a in (c:\tmp.txt) do (
if %%a LSS 2600 goto :W2k)
reg query "\\%1\HKLM\System\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections
reg add "\\%1\HKLM\System\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0
reg query "\\%1\HKLM\System\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections
goto :EOF

:W2k
Echo.
Echo Server is Windows 2000 or below, this command can only be run on XP or Windows Server 2003
Echo.
goto :EOF

:SYNTAX
ECHO.
ECHO --------------------------------------------------------------------------------------
ECHO RDP.cmd : Turn on Remote Admin mode terminal service in XP/Windows Server 2003
ECHO --------------------------------------------------------------------------------------
ECHO.
ECHO Usage: RDP.cmd servername (You must be an admin on the box)
ECHO --------------------------------------------------------------------------------------

:EOF
if exist c:\tmp.txt( del /Q c:\tmp.txt ) 1>nul 2>nul

Technorati tags: RDP, AD, Active Directory, Scripting, Wnidows