Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

VBScript check to see if a service is installed

0.00/5 (No votes)
26 Nov 2009 1  
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.

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.

VB
' Method to check if a service is installed
Public Function isServiceInstalled(ByVal svcName)
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
    
    ' Obtain an instance of the the class 
    ' using a key property value.
    
    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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here