猿问

禁用 UAC 并通知用户

我已经看过这样的线程: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!");

        }


凤凰求蛊
浏览 104回答 1
1回答

慕尼黑8549860

您在此处使用 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);
随时随地看视频慕课网APP
我要回答