1
votes

I am using the last example on this page in WMI to print out some Windows System Log information: http://msdn.microsoft.com/en-us/library/aa394593(VS.85).aspx

I would also like to print out the binary data as well, but I am not sure how to do that in WScript. Here is my modified code:

' 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

I get this error message from Windows Script Host when running test.vbs:

Error: Type mismatch, Code: 800A000D, Source: Microsoft VBScript runtime error

Any idea how to print the data out as a hex character string?

1

1 Answers

1
votes

.Data is an array of integer values (little endian encoded wide characters from the looks of it). You'd need to ChrW() each pair of numbers and concatenate them to a string before you could print the data. A function like this might work:

Function ToStr(arr)
  ToStr = ""
  For i = 0 To UBound(arr) Step 2
    ToStr = ToStr & ChrW(arr(i) + arr(i+1)*256)
  Next
End Function