在开发软件或制作安装包时,有时会需要管理员权限 ,但是又不想弹出UAC对话框。

可以编写一个小工具,检测UAC是否关闭。如果没有关闭,就自动关闭UAC。

实现比较简单,

找到注册表

计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System下的EnableLUA值,改为0。默认是1

C#实现代码如下

 1  private bool DisableUAC()
 2         {
 3             try
 4             {
 5                 string path = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System";
 6                 string uac = "EnableLUA";
 7                 RegistryKey key = Registry.LocalMachine.CreateSubKey(path);
 8                 if (key != null)
 9                 {
10                     key.SetValue(uac, 0, RegistryValueKind.DWord);
11                     key.Close();
12                 }
13 
14                 return true;
15             }
16             catch(Exception ex)
17             {
18                 MessageBox.Show(ex.Message);
19                 return false;
20             }
21         }
22 
23         private void Reboot()
24         {
25             System.Diagnostics.Process.Start("shutdown", " -r -t 0");
26         }

 

示例代码

 

相关文章:

  • 2021-10-14
  • 2021-04-28
  • 2021-12-26
  • 2022-12-23
  • 2021-09-27
  • 2021-11-30
  • 2022-03-11
  • 2022-12-23
猜你喜欢
  • 2021-12-29
  • 2022-12-23
  • 2022-02-25
  • 2021-12-29
  • 2021-10-29
  • 2021-08-08
  • 2021-08-21
相关资源
相似解决方案