Monitoring Service In Windows


Below script would monitor the service states ( start, stop, starting , stopping, paused). This script would be useful for system engineers who are using custom utilities to monitor windows services eg: Nagios

 

Working Script

strComputer = “.”
‘ You need to specify the program( you can get the exe by right click the service –> path to executable.
strProgram = “lsass.exe”

Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\” _
& strComputer & “\root\cimv2”)

‘ Below code checks the program state
Set colProcesses = objWMIService.ExecQuery _
(“SELECT * FROM Win32_Process WHERE Name = ‘” & strProgram & “‘”)
If (colProcesses.Count <> 0) Then
Wscript.Echo “The program is running on the computer”
End If

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s