Enable Remote Desktop (RDP) Remotely

This allows you to enable Remote Desktop remotely and add a Domain User to the Remote Desktop Users local group.

'Make sure to replace "<domainname>/" with your Domain name.

Const ENABLE_CONNECTIONS = 1
Dim PCName, UsrName
strComputer = InputBox("Enter computer name:",PCName)
strUser = InputBox("Type username:",UsrName)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\" & strComputer & "rootcimv2")

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

For Each objItem in colItems
errResult = objItem.SetAllowTSConnections(ENABLE_CONNECTIONS)
Next
Set objGroup = GetObject("WinNT://" & strComputer & "/Remote Desktop Users")
Set objUser = GetObject("WinNT://<domainname>/" & strUser)
objGroup.Add(objUser.ADsPath)
For Each objUser in objGroup.Members
If objUser.Name = strUser Then
Wscript.Echo strUser & " has RDP Access to computer."
End If
Next

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.