DoesServiceExist – Detect if service exist on remote host
Written in 2009 for the Windows versions of the time. Check that the tool or steps still suit your environment before using them.
- Remote host must respond to ping
DoesServiceExist - Detect if service exist on remote host
This script can be used to detect whether or not a service exist on a remote host.
I originally created it to determine if WDS is installed (ServiceName = WDSServer)
Usage: CScript.exe //nologo DoesServiceExist.vbs /Computer:HOSTNAME /ServiceName:SERVICENAME
Example: CScript.exe //nologo DoesServiceExist.vbs /Computer:CompanyServer01 /ServiceName:WDSServer
Option Explicit
On Error Resume Next
Dim strComputer
Dim strServiceName
Dim objComputer
Dim objService
strComputer = Wscript.Arguments.Named("Computer")
strServiceName = Wscript.Arguments.Named("ServiceName")
If Len(Trim(strComputer)) > 0 And Len(Trim(strServiceName)) > 0 Then
If IsOnline(strComputer) = True Then
Set objComputer = GetObject("WinNT://" & strComputer & ",computer")
If Err.Number = 0 Then
Set objService = objComputer.GetObject("service", strServiceName)
If Err.Number = 0 Then
WScript.Echo strComputer & vbTab & "Services Status" & vbTab & "Exists"
Else
WScript.Echo strComputer & vbTab & "Services Status" & vbTab & "Does not exist"
End If
Else
WScript.Echo strComputer & vbTab & "Services Status" & vbTab & "Unknown"
End If
Else
WScript.Echo strComputer & vbTab & "Services Status" & vbTab & "Offline"
End If
Else
WScript.Echo "Usage: cscript.exe //nologo DoesServiceExist.vbs /Computer:HOSTNAME /ServiceName:SERVICENAME"
End If
Function IsOnline(strComputer)
Dim objPing
Dim objStatus
Set objPing = GetObject("winmgmts:" & Chr(123) & "impersonationLevel=impersonate" & Chr(125) & "").ExecQuery("select * from Win32_PingStatus where address = '" & strComputer & "'")
For Each objStatus In objPing
If IsNull(objStatus.StatusCode) Or objStatus.StatusCode <> 0 Then
'Nothing
Else
IsOnline = True
End If
Next
End FunctionPublishers website: https://www.ittelligence.com
ITtelligence mirror: DoesServiceExist.zip (707 B)
How to Use ItLink to this section
CScript.exe //nologo DoesServiceExist.vbs /Computer:HOSTNAME /ServiceName:SERVICENAME
CScript.exe //nologo DoesServiceExist.vbs /Computer:CompanyServer01 /ServiceName:WDSServerParameter | Meaning |
|---|---|
/Computer: | Host to check. It is pinged first. |
/ServiceName: | Service key name, such as WDSServer or Spooler, not the display name. |
Output is one tab-separated line, for example CompanyServer01 Services Status Exists. The last field is Exists, Does not exist, Offline (no ping reply) or Unknown (the host replied but could not be queried). The script always exits with 0, so parse the text rather than ERRORLEVEL.
No comments yet
Comments are moderated and appear once approved.