Enable RDP (Remote Desktop Protocol) using WMI remotely
Posted in Microsoft
This allows you to enable Remote Desktop remotely and add a Domain User to the Remote Desktop Users local group.
'Make sure to replace "/" 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 & "\root\cimv2")
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:///" & 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