
正文
C#开启和关闭UAC功能
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
在制作软件安装包的时候,可以使用这个功能,关闭用户电脑UAC。
实现比较简单,
找到注册表
计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System下的EnableLUA值,改为0。默认是1。
C#实现代码如下
private bool DisableUAC()
{
try
{
string path = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System";
string uac = "EnableLUA";
RegistryKey key = Registry.LocalMachine.CreateSubKey(path);
if (key != null)
{
key.SetValue(uac, , RegistryValueKind.DWord);
key.Close();
} return true;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
} private void Reboot()
{
System.Diagnostics.Process.Start("shutdown", " -r -t 0");
}
示例代码








