我今天遇到了同样的问题,对于我的情况(非安装计划任务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