Windows事件日志VBS脚本无结果

时间:2015-08-31 14:08:38

标签: vbscript event-log

我们有PowerShell脚本设置,用于执行脱机备份。由于脚本执行不正确导致powershell提示用户想要执行的操作,因此执行这些脚本失败。由于这个原因,脚本超时了。

要检测脚本执行超时,我尝试使用VBS脚本查询事件日志,但这总是返回0结果。

我尝试使用此代码:

 LOG_FILE = "C:\jsco\Scripts\output.txt"

strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NTLogEvent WHERE Logfile = 'Microsoft-Windows-TaskScheduler/Operational' AND EventCode = '332'")
For Each objEvent in colItems     
    writeLog "Category: " & objEvent.Category
    writeLog "Category String: " & objEvent.CategoryString
    writeLog "Computer Name: " & objEvent.ComputerName
    writeLog "Data: " & objEvent.Data
    writeLog "Event Code: " & objEvent.EventCode
    writeLog "Event Identifier: " & objEvent.EventIdentifier
    writeLog "Insertion Strings: " & objEvent.InsertionStrings
    writeLog "Logfile: " & objEvent.Logfile
    writeLog "Message: " & objEvent.Message
    writeLog "Record Number: " & objEvent.RecordNumber
    writeLog "Source Name: " & objEvent.SourceName
    writeLog "Time Generated: " & objEvent.TimeGenerated
    writeLog "Time Written: " & objEvent.TimeWritten
    writeLog "Type: " & objEvent.Type
    writeLog "User: " & objEvent.User 
Next

Sub writeLog(strText)
  Dim objFSO, objLogFile

  Set objFSO = CreateObject("Scripting.FileSystemObject")  
  Set objLogFile = objFSO.OpenTextFile(LOG_FILE, 8, True)

  objLogFile.WriteLine strText
  objLogFile.Close
End Sub

我也试过这个:

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Security)}!\\" & strComputer & "\root\cimv2")

Set objWMIService = GetObject("winmgmts:{(Security)}\\" & strComputer & "\root\cimv2")

如屏幕截图所示,事件在事件日志中有效。

Eventlog Screencap http://149.210.139.155/~jef/tmp/eventlog.png

有没有人知道是什么原因以及如何解决这个问题。谢谢你的时间。

0 个答案:

没有答案