Click here to Skip to main content
12,348,674 members (52,442 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

14.6K views
5 bookmarked
Posted

VBScript check to see if a service is installed

, 26 Nov 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
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.

' 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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

s4111
South Africa South Africa
No Biography provided

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 26 Nov 2009
Article Copyright 2009 by s4111
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid