我有这段代码,但我似乎并不完全理解权限需求方法的目的
RegistryPermission registryPermission = new RegistryPermission(RegistryPermissionAccess.AllAccess, @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
registryPermission.Demand();
RegistryKey regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", RegistryKeyPermissionCheck.ReadWriteSubTree);
if (checkBoxLoadStartup.Checked)
{
//make an entry in the registry to make this program run at start up
regKey.SetValue(Application.ExecutablePath.ToString(), Application.ExecutablePath.ToString());
}
else
{
//delete the entry
regKey.DeleteValue(Application.ExecutablePath.ToString());
}
我希望看到一个窗口弹出并要求我允许写入注册表的权限。相反,我有一个例外。为了使它工作,我补充说:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
在app.manifest中现在我没有看到任何弹出窗口,但我可以更改值。
是否可以显示弹出窗口,询问问题是否有权更改注册表并基于给定的权限来修改或不修改注册表项?