C#开启和关闭UAC功能

在开发软件或制作安装包时,有时会需要管理员权限 ,但是又不想弹出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         }

示例代码

相关推荐
樂禮21 分钟前
Windows-Arch Linux 键鼠共享 & 剪贴板同步配置
linux·运维·windows
未来可期丶25 分钟前
【开发环境】Windows+Docker Desktop+WSL2最佳实践
windows·docker·docker desktop·wsl2
2501_941982059 小时前
企业微信二次开发:私域数据基石——三大核心基础能力接口实战
windows·架构·bootstrap·企业微信
wrq14717 小时前
MyAccess 完整使用手册
c#·orm框架
美丽的欣情18 小时前
RK3588 Debian 交叉编译环境搭建(Windows + VMware Debian + CMake)
运维·windows·debian
勤劳打代码19 小时前
Flutter 架构指南 —— windows 平台安装拆解
windows·架构
z落落20 小时前
C# WinForm 自定义控件
开发语言·c#
lzhdim1 天前
20260714 - 个人小作品更新
c#·notenet
aramae1 天前
C++11:现代C++的里程碑
c语言·开发语言·c++·windows·git·后端
执行x1 天前
wsl2安装+桥接模式+固定IP
linux·windows·ubuntu