我正在使用WMI此页面上的最后一个示例打印出一些Windows系统日志信息: http://msdn.microsoft.com/en-us/library/aa394593(VS.85).aspx
我也想打印出二进制数据,但我不确定如何在WScript中执行此操作。这是我修改过的代码:
' test.vbs
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent " _
& "Where Logfile = 'System' and SourceName = 'MySource'")
For Each objEvent in colLoggedEvents
Wscript.Echo "Category: " & objEvent.Category & VBNewLine _
& "Event Code: " & objEvent.EventCode & VBNewLine _
& "Message: " & objEvent.Message & VBNewLine _
& "Time Written: " & objEvent.TimeWritten & VBNewLine _
& "Event Type: " & objEvent.Type & VBNewLine _
& "Binary Data: " & objEvent.Data
Next
运行test.vbs时,我从Windows脚本宿主收到此错误消息:
错误:类型不匹配,代码:800A000D,来源:Microsoft VBScript运行时错误
知道如何以十六进制字符串形式打印数据吗?
答案 0 :(得分:1)
.Data
是一个整数值数组(从它的外观看小端编码的宽字符)。在打印数据之前,您需要ChrW()
每对数字并将它们连接成一个字符串。像这样的函数可能有效:
Function ToStr(arr)
ToStr = ""
For i = 0 To UBound(arr) Step 2
ToStr = ToStr & ChrW(arr(i) + arr(i+1)*256)
Next
End Function