Will accept to all. There is a script that performs the function described above. If I run it through PowerShell, will I get an error in the item “once in 10 seconds”? And do I understand correctly (at least partially the code)? Explain incomprehensible moments.

Dim oLocator, oSvc, oColServices, oService // переменные Set oLocator = CreateObject("wbemScripting.Swbemlocator") // создаем объект Swbemlocator Set oSvc = oLocator.ConnectServer() // соеденяемся с сервером Set oColServices = oSvc.ExecNotificationQuery _ // что-то с оповещением ("Select * from __instancemodificationevent " _ & "within 10 where TargetInstance isa 'Win32_Service'") // событийный запрос с интервалом в 10 секунд Do Set oService = oColServices.NextEvent // ??? WScript.Echo oService.TargetInstance.Name & vbTab & vbTab & _ oService.TargetInstance.State Loop 
  • is the question really so stupid? - Muscled Boy
  • By the way, I started the script, it works, it floods the message about starting the services stop. The main thing is to know how to turn it off :) but this is the second question. I killed him through the process manager quickly. - Albert Fomin
  • @AlbertFomin, I can not boast of skills in the field of administration. In general, I get an error, writes line 4 character 96 - an invalid character . Is this due to a space? There it should not be? And why are " _ " used? - Muscled Boy
  • I wrote everything in one line, where it is possible, _ this is a gluing line in a visual of BASIC. But there is no such thing in povershell, he most likely swears at this. In command environments, one line, one command. - Albert Fomin
  • @AlbertFomin, good. Removed underscore, now writes " method is not supported by ExecNotificationQuery object " (line 4, symbol 1). - Muscled Boy

1 answer 1

A specific question concerns WMI events ,

ExecNotificationQuery - assigns oColServices an event receiver

__instancemodificationevent - type of event for which changes are trapped.

TargetInstance isa 'Win32_Service' - service status changes are TargetInstance isa 'Win32_Service' .

Within - is responsible for the polling interval, that is, theoretically every 10 seconds a script should be run.

NextEvent - transition to the next object (code to handle the next event)

oService.TargetInstance.State - service state