Need a VB Script to check if service exist

Posted by Shorabh Upadhyay on Stack Overflow See other posts from Stack Overflow or by Shorabh Upadhyay
Published on 2013-10-25T09:37:08Z Indexed on 2013/10/25 9:54 UTC
Read the original article Hit count: 157

Filed under:
|

I want to write a VBS script which will check if specific service is installed/exist or not locally.

If it is not installed/exist, script will display message (any text) and disabled the network interface i.e. NIC.

If service exist and running, NO Action. Just exit.

If service exist but not running, same action, script will display message (any text) and disabled the network interface i.e. NIC.

i have below given code which is displaying a message in case one service is stop but it is not -

  1. Checking if service exist or not
  2. Disabling the NIC

    strComputer = "."
    Set objWMIService = Getobject("winmgmts:"_
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colRunningServices = onjWMIService.ExecQuery _
        ("select State from Win32_Service where Name = 'dhcp'")
    
    For Each objService in colRunningServices
        If objService.State <> "Running" Then
            errReturn = msgbox ("Stopped")
        End If
    Next
    

Please help. Thanks in advance.

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about vbscript