VBS Script – Remotely Enable Remote Desktop (RDP)

The following VBS Script can be used to remotely ENABLE or DISABLE Remote Desktop (RDP).

It is compatible with Windows 7 systems.

Whilst Group Policy is the recommended method for configuring Remote Desktop on multiple systems, this script may come in handy when you need to immediately configure RDP on a particular system.

How it works:

When you run the script it will prompt for the computer machine name (network name)

VBS-EnableRDP1

It will then display whether it is currently ENABLED or DISABLED and ask if you want to change this.

VBS-EnableRDP2

Download: here (note, you will need to rename as a .vbs file)

VBS Script:

' This script will enable or disable remote desktop  on a remote system
' Pat Fiannaca

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = InputBox("Enter the MACHINE NAME on which you would like to enable or disable Remote Desktop:")

If strComputer = "" Then
  WScript.Quit
End If

Set StdOut = WScript.StdOut

On Error Resume Next

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
strComputer & "\root\default:StdRegProv")
If Err.Number <> 0 Then
  WScript.Echo "An error has occurred.  You may have mistyped the computer name." 
  WScript.Quit
End If

strKeyPath = "SYSTEM\CurrentControlSet\Control\Terminal Server"
strValueName = "fDenyTSConnections"

oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue

If dwValue = 1 Then
  prompt = MsgBox ("Remote Desktop is Currently disabled.  Do you want to ENABLE it?", vbYesNo)
  If prompt = vbYes then
    dwValue = 0
    oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue 
     WScript.Echo "Remote Desktop is now ENABLED on " & strComputer
    WScript.Quit
  ElseIf prompt = vbNo then
    WScript.Echo "Remote Desktop is still DISABLED."
   Wscript.Quit 
  End If
ElseIf dwValue = 0 then
  prompt = MsgBox ("Remote Desktop is Currently ENABLED.  Do you want to DISABLE it?", vbYesNo)
  If prompt = vbYes then
    dwValue = 1
    oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
    WScript.Echo "Remote Desktop is now DISABLED on " & strComputer
    WScript.Quit
  ElseIf prompt = vbNo then
    WScript.Echo "Remote Desktop is still ENABLED." 
    WScript.Quit
  End If
End If

Source: http://community.spiceworks.com/scripts/show/302-enable-or-disable-rdp-remote-desktop-on-remote-system-vbs