Validation in Windows Event Logs

Ranorex Studio, Spy, Recorder, and Driver.
itchy20
Posts: 5
Joined: Mon Nov 21, 2011 6:12 pm

Validation in Windows Event Logs

Post by itchy20 » Tue Jul 24, 2012 12:24 pm

I have an automated Ranorex solution which installs a large SW package, I then validate certain file locations etc. I also want to be able to use Ranorex to validate that there are no errors in the windows event log before it proceeds with my baseline verification tests.

I want to know the best way of doing this, the problem I have is that it needs to work across multiple O/S from Win XP to Win 7 and Server 2008R2.

Is there a way to read the content of the log files direct, without having to navigate the GUI for the event viewer (which is different on different O/S)

Open to suggestions if you have done anything like this before, I'm not sure how to approach it.....

Patrik
Posts: 17
Joined: Fri Sep 02, 2011 2:56 pm

Re: Validation in Windows Event Logs

Post by Patrik » Tue Jul 24, 2012 3:46 pm

Hi Itchy,
you can do this via the WMI Interface of Microsoft... e.g.:

This would be the VB Source code to get all messages in the event log. There is a very useful tool called "WMICodeCreator" (you can download it from microsoft) which generates you this source (even in C#) with drag and drop. So via an user interface you can select the information you want and the source is generated.

You can use this code then within an code module in Ranorex. Hope this helps ?
Cheers,
Patrik

Code: Select all

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent " _
        & "Where Logfile = 'System'")
For Each objEvent in colLoggedEvents
    Wscript.Echo "Category: " & objEvent.Category & VBNewLine _
    & "Computer Name: " & objEvent.ComputerName & VBNewLine _
    & "Event Code: " & objEvent.EventCode & VBNewLine _
    & "Message: " & objEvent.Message & VBNewLine _
    & "Record Number: " & objEvent.RecordNumber & VBNewLine _
    & "Source Name: " & objEvent.SourceName & VBNewLine _
    & "Time Written: " & objEvent.TimeWritten & VBNewLine _
    & "Event Type: " & objEvent.Type & VBNewLine _
    & "User: " & objEvent.User
Next

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Validation in Windows Event Logs

Post by artur_gadomski » Wed Jul 25, 2012 7:35 am

You can also look into System.Diagnostics.EventLog:
http://msdn.microsoft.com/en-us/library ... ntlog.aspx