我使用此代码在远程计算机上获取已安装的 .NET 版本。使用 Windows 7 它可以完美运行,但使用 Windows 10 会引发以下异常
System.Security.SecurityException:不允许请求的注册表访问。
代码示例
using (RegistryKey remoteHklm = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, hostName))
{
using (RegistryKey serviceKey = remoteHklm.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full", true))
{
if (serviceKey != null)
{
version = serviceKey.GetValue("Version").ToString();
}
else
{
version = "error on get version from registry";
}
}
}
您在 Windows 10 上没有对此注册表项的写访问权限。将第二个OpenSubKey
参数改为false
,即可在注册表编辑器中查看该键的权限。
using (RegistryKey serviceKey = remoteHklm.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full", false))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句