开发者

VBscript checking for events in lifetime of script

开发者 https://www.devze.com 2023-04-05 03:21 出处:网络
I have a vbScript which I use to stop, start and restart services.It works but I have one little niggle.I hoped to be able to watch for the Service State change events (7036) in the Event log by

I have a vbScript which I use to stop, start and restart services. It works but I have one little niggle. I hoped to be able to watch for the Service State change events (7036) in the Event log by

StartTime=CDate(Now())

.... service stop/start commands etc

Set colServiceEvents = objWMIService.ExecQuery _
       ("Select * from Win32_NTLogEvent " _
           & "Where Logfile = 'System'" _
           & " and EventCode = '7036'" _
        & " and TimeWritten >'" & StartTime & "'" )

By fiddling the StartTime I can see 7036 Events in the last few minutes but I can't seem to see service state change events within the life of the script. Am I missing something or this a windows "feature"?

To be clear the script works and I can verify the status by query on Win32_Service but I'd like to know for 开发者_开发百科future reference. "There's more than 1 way to skin a cat in vbscript but most of them seem to involve a chain gun and a mincer"


I guess the issue is related to the date-time values​​.
Look at the article (especially part Converting VBScript dates to WMI Dates) from : http://www.aspfree.com/c/a/Windows-Scripting/Working-with-Dates-in-WMI/

0

精彩评论

暂无评论...
验证码 换一张
取 消