我已经看过这样的线程: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 关注
- 103 浏览
添加回答
举报
0/150
提交
取消