'========================================================================== ' NAME: EnableTSRDP.vbs ' ' AUTHOR: Alan Kaplan , alan dot kaplan at va dot gov ' DATE : 3/22/2006 ' ' COMMENT: Minor changes from code below. Works to enable Remote ' Desktop on XP, Admin Term services on server Option Explicit Dim strComputer, errmessage, message Dim strWMI, oWMI, strQuery, iValue Dim items, item, retval If WScript.Arguments.Count = 1 Then strComputer = WScript.Arguments(0) Else Dim WshShell Set wshShell = WScript.CreateObject("WScript.Shell") strComputer = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%") message = "Enable Admin Terminal Services on what Windows 2003 Server, or Remote Desktop on what XP workstation?" strComputer = InputBox(message,"Name?",strComputer) End If If strcomputer = "" Then WScript.Quit strComputer = UCase(strComputer) errMessage = " No changes to " & strComputer 'see http://blogs.msdn.com/saveenr/archive/2005/11/24/496812.aspx strWMI = "WINMGMTS:" & "\\" & strComputer & "\root\cimv2" strQuery = "select * from Win32_TerminalServiceSetting" iValue = 1 ' 0=off, 1=On On Error Resume Next set oWMI = GetObject(strWMI) If Err <> 0 Then If Len(err.Description) > 1 Then errmessage = Err.Description ErrMsg("Failed. " & errMessage) End If set items = oWMI.ExecQuery(strQuery) for each item in items If Err <> 0 Then If Len(err.Description) > 1 Then errmessage = Err.Description ErrMsg("Failed. " & errMessage) End If retval = item.SetAllowTSConnections(iValue) Next If retval = 0 Then message = "Success. It will take a few seconds before the system is ready." & _ VbCrLf & VbCrLf & "Do you want to connect to " & strComputer & "? (There will be a delay of 5 seconds)" retval = MsgBox(message, vbYesNo,"Connect now?") If retval = vbYes Then WScript.Sleep 5000 WshShell.Run "%windir%\system32\mstsc.exe /v:" & strComputer,1,False End If Else ErrMessage "Failed to enable remote access on " & strcomputer End If Sub ErrMsg(strMessage) MsgBox strMessage,vbCritical + vbokonly,"Fatal Error" WScript.Quit End Sub