' Asynchronously monitor service modification events.



strComputer = "."
Set SINK = WScript.CreateObject("WbemScripting.SWbemSink","SINK_")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
objWMIService.ExecNotificationQueryAsync SINK, _
"SELECT * FROM __InstanceModificationEvent WITHIN 1 " & _
"WHERE TargetInstance ISA 'Win32_Service'"
WScript.Echo "Waiting for service to be modified ..."
Do
   WScript.Sleep 1000
Loop

Sub SINK_OnObjectReady(objLatestEvent, objAsyncContext)

Wscript.Echo VbCrLf & "Service Name: " & objLatestEvent.TargetInstance.Name
Wscript.Echo "Status: " & objLatestEvent.TargetInstance.State
Wscript.Echo "Startup Type: " & objLatestEvent.TargetInstance.StartMode
Wscript.Echo "Time: " & Now

End Sub
search for scripts

VbsEdit contains all these sample scripts!





Home   Scripts

Copyright © 2001-2020 adersοft