當我運行下面的代碼,我得到異常未處理System.Security.SecurityException:「請求的註冊表訪問是不允許的」。 我有所有必要的機器訪問權限。請求註冊表不允許
namespace EventViewer
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcom to Event Log Viewer");
Console.WriteLine("Please enter Retrieve to Retrieve EventLogs");
string Retrieve = Console.ReadLine();
string Logs = Retrieve;
switch (Logs)
{
case "Retrieve":
EventLog eventLog;
eventLog = new EventLog();
eventLog.Log = "Security";
eventLog.Source = "Security-Auditiing";
eventLog.MachineName = "Cheetah";
var count = 0;
foreach (EventLogEntry log in eventLog.Entries)
{
if (count > 200)
{
return;
}
Console.Write("eventLog.Log: ", eventLog.Log);
}
break;
}
}
}
}
您可能需要爲程序管理員權限..我跑這個擁有管理員權限並沒有得到問題.. –