For the most part WMI won't return anything that doesn't exist and VBscript doesn't have the means to exit gracefully from this even when using On Error Resume Next
. I'm merely posting this because it seemed to be a common problem to which no quick answer could be found. Hope this helps someone.
Public Function isServiceInstalled(ByVal svcName)
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
isServiceInstalled = FALSE
svcQry = "SELECT * from Win32_Service"
Set objOutParams = objWMIService.ExecQuery(svcQry)
For Each objSvc in objOutParams
Select Case objSvc.Name
Case svcName
isServiceInstalled = TRUE
End Select
Next
End Function