Thursday, February 28, 2013

Get service status

You can use this vbs script if you need to know the status of a particular windows service:

Option Explicit
Dim ComputerObj, aService
Dim strComputer, objNetwork
Dim ServiceName
 
 
If WScript.Arguments.count < 1 then
  WScript.Echo "usage: StopSvc.vbs ServiceName"
  WScript.Quit
end If
 
ServiceName = WScript.Arguments.Item(0)
 
Set objNetwork = WScript.CreateObject("WScript.Network")
 
Set aService = GetObject("WinNT://" & objNetwork.ComputerName & "/" & ServiceName & ",Service")
Wscript.echo aService.DisplayName
    
If aService.Name = ServiceName Then
'    WScript.Echo "Service display name = " & aService.DisplayName     
'    WScript.Echo "Service name = " & aService.Name     
'    WScript.Echo "Service account name = " & aService.ServiceAccountName     
'    WScript.Echo "Service executable   = " & aService.Path     
'    WScript.Echo "Current status       = " & aService.Status     
    If aService.Status=4 Then
'      WScript.Echo ServiceName & " is ON: Stopping Service"
       'stopping service
       aService.stop
    End If
End if 
 
WScript.Quit


You can get more info here: http://msdn.microsoft.com/es-es/library/windows/desktop/aa746328%28v=vs.85%29.aspx