Rambeaux007
IS-IT--Management
I am working on code that will check to see if the service exists. If it does then output the status. If it does not exist just output that it is not installed. I found some other code but cannot seem to get it to function. I get a error message of "Item does not support count function".
Can someone please shed some light on this?
Option Explicit
Dim colItems, colItem, objItem, ServiceStatus, WMI_Service_Exists
Dim objWMIService, strComputer, oReg, strServiceName, colServiceList
strServiceName = "SomeService"
Set colServiceList = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = colServiceList.ExecQuery("Select * from Win32_Service where name = '" & strServiceName & "'",,48)
If (Err.Number = 0) And IsObject(colServiceList) Then
If colServiceList.Count > 0 Then
'WriteOut " The " & strServiceName & " service exists."
For Each objItem in colItems
WScript.Echo (objItem.Displayname & " = " & VbTab & objItem.State)
Next
'Set the function return value
WMI_Service_Exists = True
Else
'Set the function return value
WMI_Service_Exists = False
WriteOut " The " & strServiceName & " service does not exist."
End If
End If
Can someone please shed some light on this?
Option Explicit
Dim colItems, colItem, objItem, ServiceStatus, WMI_Service_Exists
Dim objWMIService, strComputer, oReg, strServiceName, colServiceList
strServiceName = "SomeService"
Set colServiceList = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = colServiceList.ExecQuery("Select * from Win32_Service where name = '" & strServiceName & "'",,48)
If (Err.Number = 0) And IsObject(colServiceList) Then
If colServiceList.Count > 0 Then
'WriteOut " The " & strServiceName & " service exists."
For Each objItem in colItems
WScript.Echo (objItem.Displayname & " = " & VbTab & objItem.State)
Next
'Set the function return value
WMI_Service_Exists = True
Else
'Set the function return value
WMI_Service_Exists = False
WriteOut " The " & strServiceName & " service does not exist."
End If
End If