Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does the Service Exist 1

Status
Not open for further replies.

Rambeaux007

IS-IT--Management
May 4, 2005
23
US
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
 
Code:
...
Set colItems = colServiceList.ExecQuery("Select * from Win32_Service where name = '" & strServiceName & "'",,48)
WMI_Service_Exists = False
For Each objItem in colItems
    WScript.Echo   (objItem.Displayname  & " = " & VbTab & objItem.State)
    WMI_Service_Exists = True
Next
If Not WMI_Service_Exists Then
    WriteOut "    The " & strServiceName & " service does not exist."
End If
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top