gpt4 book ai didi

c# - 如何在 C#.net 中读取 Windows XP 中的事件查看器日志

转载 作者:太空宇宙 更新时间:2023-11-03 12:40:05 26 4
gpt4 key购买 nike

我正在使用以下 XML 查询从事件查看器中读取过去 24 小时内的系统“开启事件”。

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

它在 Windows 7 及更高版本上运行良好,但在 Windows XP 上,我收到以下错误:

Error:Operation is not supported on this platform

有人可以帮助从 C#.net 中的事件查看器读取 Windows XP 中的 Turn On 事件吗?

最佳答案

XPpath 过滤首先出现在 Vista 中。对于 XP,您将不得不使用另一个实现 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
}
}
}

关于c# - 如何在 C#.net 中读取 Windows XP 中的事件查看器日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39392136/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com