vbs监视出现指定的报错就执行某一段批处理- strComputer = "."
- Set ws = CreateObject("WScript.Shell")
- set wmi = GetObject("winmgmts:\\"&strComputer&"\root\cimv2")
- set Sink = WScript.CreateObject("WbemScripting.SWbemSink", "Sink_")
- wmi.ExecNotificationQueryAsync Sink, _
- "SELECT * FROM __InstanceCreationEvent WITHIN 1 where " _
- & "TargetInstance ISA 'Win32_NTLogEvent' and " _
- & "TargetInstance.Logfile = 'System' and " _
- & "TargetInstance.EventType = '1' "
- do : WScript.Sleep 1000 : loop
-
- sub Sink_OnObjectReady(objWbemObject, objAsyncContext)
- s = objWbemObject.TargetInstance.GetObjectText_()
- 'WScript.Echo s
- ws.Environment("process")("tab") = vbTab
- ws.Environment("process")("_log") = s
- ws.Run "a.bat" 'a.bat中可以访问 _log 环境变量
- end sub
复制代码
|