Thursday, January 10, 2008

Enable or Disable Remote Desktop on Multiple Computers

This script will enable or disable Remote Desktop on multiple computers on an IP segment. The first input box asks for the subnet (i.e. 192.168.1). The second input box asks for the lowest number on the segment that you would like to start with. The third box asks for the highest number on the segment that you want to end with. I would like to add more to this script that will allow it to ping an IP address first. If there is no response it will move on to the next address instead of trying to enable RD on a non-existent PC. I will add that when I have time.


'http://vbsbob.blogspot.com/
DIM strComputer, strIPInput, strLow, strHigh
On Error Resume Next
Set WshShell = WScript.CreateObject("WScript.Shell")

'Set to 0 to disable Remote Desktop, set to 1 to enable Remote Desktop
Const ENABLE_CONNECTIONS = 1

strIPInput = InputBox("What is the subnet? Format as XX.YY.ZZ.")
strLow = InputBox("What is the low address in the range?")
strHigh = InputBox("What is the highest address in the range?")

If Right(strIPInput,1) <> "." Then
strIPInput = strIPInput & "."
End If

If strIPInput = "" OR strLow = "" OR strHigh = "" OR strHigh > 254 Then
Wscript.Echo "Invalid input - Script Cancelled"
wscript.Quit
End If

For i = strLow to strHigh

strComputer = strIPInput & i

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery ("Select * from Win32_TerminalServiceSetting")

For Each objItem in colItems
errResult = objItem.SetAllowTSConnections(ENABLE_CONNECTIONS)
Next
Next

WshShell.Popup "Complete", 10, "Remote Desktop Status", 64

1 comment:

Unknown said...

Found very cool and unique info here in this blog. This is a great addition in my favorite blog list.

Dell - Inspiron 14" Touch-Screen Laptop - 8GB Memory - 500GB Hard Drive - Silver Aluminum (17437T-2509SLV)