How to control the state of a service in win2000?

  • Thread starter Thread starter Kenshiro
  • Start date Start date
K

Kenshiro

Hi
I would like to know if exist a way to control the state of a service
in win2000? for example a program (Microsoft or freeware) that send a
popup message if the service "Server" is stopped.
Can you help me?

Thanks
Ken
 
Hi
I would like to know if exist a way to control the state of a service
in win2000? for example a program (Microsoft or freeware) that send a
popup message if the service "Server" is stopped.
Can you help me?

Thanks
Ken


See tip 3014 in the 'Tips & Tricks' at http://www.jsiinc.com

Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
Kenshiro said:
I would like to know if exist a way to control the state of a service
in win2000? for example a program (Microsoft or freeware) that send a
popup message if the service "Server" is stopped.
Can you help me?

Hi

You can use WMI to monitor the state change of a service.

Try the vbscript below (put it in a file with .vbs as file extension name,
will loop forever until terminated).


' Name of service to monitor, note, this is NOT the display name
strServiceName = "LanmanServer"

strComputer = "." ' use . for local computer

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService. _
ExecNotificationQuery("Select * from __instancemodificationevent " _
& "within 5 where TargetInstance isa 'Win32_Service' " _
& "AND TargetInstance.Name = '" & strServiceName & "'")
i = 0
Do While i = 0
Set objService = colServices.NextEvent
If objService.TargetInstance.State <> objService.PreviousInstance.State Then
Wscript.Echo objService.TargetInstance.Name _
& " is " & objService.TargetInstance.State _
& ". The service previously was " & _
objService.PreviousInstance.State & "."
End If
Loop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top