Kenshiro wrote:
> 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
--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide:
http://www.microsoft.com/technet/scriptcenter