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.....
Validation in Windows Event Logs
Re: Validation in Windows Event Logs
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
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
- artur_gadomski
- Posts: 207
- Joined: Mon Jul 19, 2010 6:55 am
- Location: Copenhagen, Denmark
- Contact:
Re: Validation in Windows Event Logs
You can also look into System.Diagnostics.EventLog:
http://msdn.microsoft.com/en-us/library ... ntlog.aspx
http://msdn.microsoft.com/en-us/library ... ntlog.aspx