c# - 从 C# 应用程序调用 OpenSubKey 时,出现安全异常错误并且应用程序未启动
问题描述
从 C# 应用程序调用 OpenSubKey Registry 函数时,出现以下异常并且由于此应用程序未启动。
应用程序:EMR.exe 框架版本:v4.0.30319 描述:进程因未处理的异常而终止。异常信息:Microsoft.Win32.RegistryKey.OpenSubKey(System.String, Boolean) 处 System.ThrowHelper.ThrowSecurityException(System.ExceptionResource) 处的 System.Security.SecurityException
下面是传递到 openSubkey HKEY_LOCAL_MACHINE\SOFTWARE\EMR\4.01.00\Technical Data 的注册表项值
还有一件事是,第一次安装后,我可以启动应用程序。但是一旦重新启动机器,然后在尝试启动时,我就会看到这个错误。
下面是代码片段:
public RegistryKey GetRegKeyHandle(String key)
{
key = BASE_REG_KEY + "\\" + key;
if (MainFrame.GetUIControlObject().MGDIsAdmin())
{
MessageBox.Show("Entered to MGDIsAdmin");
regWritable = true;
RegistryKey rkTest = Registry.LocalMachine.OpenSubKey(key, true);
return rkTest;
}
else
{
return Registry.LocalMachine.OpenSubKey(key);
}
}
请帮助我为什么仅在重新启动后才引发安全异常?
解决方案
推荐阅读
- laravel - Laravel 路由、api 和 web 用例
- php - 将来自不同数组的随机值插入 MySQL 表中的列
- python - Flask WTForms - 基于多个表单字段的自定义验证器
- c# - 在 C# 中将正则表达式与字符串连接起来
- python - 为什么这个查询在使用 flaskext.mysql 时没有正确执行,当它使用 MySQL 工作台正确执行时?
- javascript - 如何将导航栏放在引导程序 4 中 jumbtron 的正下方
- python - 鹡鸰错误新模型。models.py 中的CharField
- flutter - 如何摆脱 AnimatedContainer 上的溢出错误?
- javascript - 从 nodeList javascript 获取数据集值
- api - 如何在 Flutter 中设置定时器来定期更新 API 数据