我已經看過這樣的線程:Disabling UAC programmatically但是它們有點舊,似乎我做不到。我正在嘗試創建一個 Windows 工具來幫助用戶執行某些過程(例如啟用或禁用 UAC)。到目前為止,這是我的代碼,即使管理員正確,它也不會調低或調高 UAC 值。現在我沒有使用管理員帳戶(Windows 10),但我確實可以訪問本地管理員憑據。try { RegistryKey uac = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true); if (uac == null) { uac = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"); } uac.SetValue("EnableLUA", 0); uac.Close(); } catch (Exception) { MessageBox.Show("Error!"); }
1 回答

慕尼黑8549860
TA貢獻1818條經驗 獲得超11個贊
您在此處使用 Registry.CurrentUser,請改用 LocalMachine。所以代碼會是這樣的:
RegistryKey uac = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
if (uac == null)
{
uac = Registry.LocalMachine.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");
}
uac.SetValue("EnableLUA", 0);
- 1 回答
- 0 關注
- 125 瀏覽
添加回答
舉報
0/150
提交
取消