3
看看下面的C#代碼:GetEventLogs()返回沒有安裝事件日誌?
EventLog[] eventLogs;
eventLogs = EventLog.GetEventLogs(computername);
foreach (EventLog evt in eventLogs)
{
statusMessagesListBox.Items.Add("evt.Log.ToString(): " + evt.Log.ToString() + "\t\tevt.LogDisplayName: " + evt.LogDisplayName);
}
當我運行的是,我的輸出是這樣的:
evt.Log.ToString(): Application evt.LogDisplayName: Application
evt.Log.ToString(): HardwareEvents evt.LogDisplayName: Hardware Events
evt.Log.ToString(): Security evt.LogDisplayName: Security
等等,這樣的。但爲什麼沒有安裝日誌?此外,當我嘗試運行此代碼:
var eventLog = new EventLog("Setup", computer);
eventLog.Clear();
eventLog.Dispose();
我得到的日誌「設置」未在該計算機上存在的錯誤消息,即使它絕對不會。以上代碼適用於除安裝程序日誌以外的所有其他事件日誌。
如何訪問安裝程序事件日誌?
作爲參考,正在嘗試的.NET框架是4.0和4.5,目標計算機是Windows 7和2008 R2。
你釘了它。謝謝。這正是我所需要的。 –