我有一个应用程序,需要获取最后一次关机时间。我使用 EventLog 类来获取关机时间。我有单独的类文件,旨在读/写事件日志。ReadPowerOffEvent 函数旨在获取电源关闭事件。
public void ReadPowerOffEvent()
{
EventLog eventLog = new EventLog();
eventLog.Log = logName;
eventLog.MachineName = machineName;
if (eventLog.Entries.Count > 0)
{
for (int i = eventLog.Entries.Count - 1; i >= 0; i--)
{
EventLogEntry currentEntry = eventLog.Entries[i];
if (currentEntry.InstanceId == 1074 && currentEntry.Source=="USER32")
{
this.timeGenerated = currentEntry.TimeGenerated;
this.message = currentEntry.Message;
}
}
}
}
但是每当它试图获取事件条目计数时,它就会抛出一个 IOException 说“找不到网络路径”。我试图解决,但我失败了。请帮帮我...