'isTermServer.vbs alan dot kaplan at va dot gov 'Check whether server is a Terminal Server '11/12/2009 Option Explicit Dim WshShell Dim strComputer Dim bNotFound, bEcho Set wshShell = WScript.CreateObject("WScript.Shell") 'set to true to echo results bEcho = True GetArgs() If isTermServer() Then If bEcho Then wscript.Echo strComputer & " is a terminal server." WScript.Quit(1) Else If bNotFound Then WScript.Quit(100) 'Set errorlevel 100 on exit If bEcho Then Wscript.Echo strComputer & " is NOT a terminal server." WScript.Quit(0) End If ' ======== Functions and Subs ========== Function isTermServer () Const HKLM = &H80000002 Const strPath = "SYSTEM\CurrentControlSet\Control\Terminal Server" Dim strEntry, objReg, intValue strEntry ="TSAppCompat" '0 is Remote Administration, 1 is Application Server mode On Error Resume Next Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv") If Err <> 0 Then bNotFound = True Else objReg.GetDWORDValue HKLM, strPath, strEntry, intValue 'if bEcho Then Wscript.Echo strEntry & " value: " & intValue End If If bNotFound Then If bEcho Then Wscript.Echo strComputer & " Not Found." Exit Function Else If intValue = 0 Then isTermServer = False If intValue = 1 Then isTermServer = True End If End Function Sub GetArgs() If WScript.Arguments.named.exists("computer") Then strComputer = WScript.Arguments.Unnamed(0) Else Syntax() End If End Sub Sub Syntax() Dim Message Message = WScript.ScriptName & " checks whether a local or remote server is a Terminal server. " & VbCrLf & VbCrLf & _ "It is designed to be run in a batch file, and sets an errorlevel on exiting." & VbCrLf & VbCrLf & _ "Example: cscript " & WScript.ScriptName & " /computer RemoteComputerName" & VbCrLf & VbCrLf & _ "for local server, use:" & VbCrLf & _ "cscript " & WScript.ScriptName & " /computer %ComputerName%" & VbCrLf & VbCrLf & _ "ERRORLEVELs: 1 if isTermServer is true, 0 if isTermServer is false, 100 if group does not exist." & VbCrLf & VbCrLf & _ "Batch file example: " & VbCrLf & VbCrLf & _ "cscript isTermServer.vbs /computer computername" & VbCrLf & _ "if %errorlevel% == 100 echo Computer not found" & VbCrLf & _ "if %errorlevel% == 1 echo Terminal Server" & VbCrLf & _ "if %errorlevel% == 0 echo Not a Terminal Server" & VbCrLf & VbCrLf & _ "Written by Alan Kaplan, www.akaplan.com/blog" MsgBox Message,vbInformation + vbOKOnly,WScript.ScriptName & " Syntax and Usage" WScript.Quit End Sub