我今天遇到了同樣的問題,對於我的情況(非安裝計劃任務exe),沒有任何WinForms或ASPX的答案似乎可行。所以我這樣做: -
protected void prog_Load(object sender, EventArgs e)
{
boolean setupComplete = false;
try // setting an Event log entry, just to see if we can
{
logEvent = "prog started";
EventLog.WriteEntry(logSource, logEvent, EventLogEntryType.Information, 0);
setupComplete = true;
}
catch (Exception eLog1) // we can't, so try to fix
{
try
{
EventLog.CreateEventSource(logSource, logLog);
logEvent = "prog registered for Event Logging";
EventLog.WriteEntry(logSource, logEvent, EventLogEntryType.Information, 0);
}
catch (Exception eLog2) // aha! we probably lack admin rights to set the registry key
{
MessageBox.Show("prog needs admin rights the first time it runs", "prog Setup", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
// run
if (setupComplete == true)
{
DoTheWork();
}
// exit
this.Close();
}
我的應用程序不需要管理員權限,只需要安全分支的讀訪問權限。 – Sam 2012-07-16 20:05:06
只有擁有管理員或域權限(只讀)的用戶才能使用「設計」安全分支。以編程方式繞過這一點,您可能需要更改「註冊表設置」。 KB附加:http://support.microsoft.com/kb/323076 – 2012-07-16 20:16:02