Reputation: 23
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) <= 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?
Upvotes: 2
Views: 676
Reputation: 2626
Filtering by XPpath
was introduced first with Vista
. For XP
you would have to use another implementation using EventLog
class.
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
}
}
}
Upvotes: 1