Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Script to find the service and manage its state

$
0
0

We have a service that runs with different names on different machines like

Bomgar-scadsadccd, Bomgarsdscchfn, Bomgarscnkfkdk

So, here we need to write a VB script that will find this service with partial name "Bomgar" and check it's status like

1) Not present, then should install from a shared folder like "start \10.216.16.245\Bomgar.exe"

2) Installed but not running, then start the service.

3) Installed and running then quit.

How can we achieve this? This is what i have tried..

"strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service
where Name='bomgar*'")
nItems = colRunningServices.Count
    If nItems > 0  Then
For Each objItem in colRunningServices
    If objItem.State = "Stopped" Then objItem.startservice            
            ElseIf objItem.State = "Running" Then exit
               
End If
    Next
Else
        start \\10.18.23.245\Shared\Bomgar.exe
End If



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>