2

I'm using the below XML Query to read system "Turn on event" from event viewer in last 24 hours.

string query = "<QueryList>" +
                "<Query Id=\"0\" Path=\"System\">" +
                "<Select Path=\"System\">*[System[(EventID=6005) and TimeCreated[timediff(@SystemTime) &lt;= 86400000]]]</Select>" +
                "</Query>" +
                "</QueryList>";

It works well on Windows 7 and above but on Windows XP, I'm getting the below error:

Error:Operation is not supported on this platform

Can someone please help in reading the Turn On event in Windows XP from event viewer in C#.net?

rene
  • 41,474
  • 78
  • 114
  • 152

1 Answers1

1

Filtering by XPpath was introduced first with Vista. For XP you would have to use another implementation using EventLog class.

Example:

EventLog aLog = new EventLog();
aLog.Log = "Application";
aLog.MachineName = ".";  // Local machine

string message = "\'Service started\'";

foreach (EventLogEntry entry in aLog.Entries)
{
    if (entry.Source.Equals("tvNZB")
     && entry.EntryType == EventLogEntryType.Information)
    {
        if (entry.Message.EndsWith(message))
        {
            //write it somewhere
        }
    }
}
Community
  • 1
  • 1
Janis S.
  • 2,526
  • 22
  • 32