C# 使用 Windows 10 访问远程注册表不起作用 [英] C# Access Remote Registry with Windows 10 not work

查看:58
本文介绍了C# 使用 Windows 10 访问远程注册表不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码在远程计算机上获取已安装的 .NET 版本.在 Windows 7 中它运行良好,但在 Windows 10 中抛出以下异常

I use this code to get the installed .NET Version on a remote machine. With Windows 7 it works perfect but with Windows 10 the following exception throws

System.Security.SecurityException:不允许请求的注册表访问.

System.Security.SecurityException: Requested registry access is not allowed.

  • 使用 i connect 的用户在管理员组中
  • 服务RemoteRegistry"设置为启动类型手动"
  • 代码示例

    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,即可在注册表编辑器中查看该键的权限.

    You have with Windows 10 no write Access to this registry key. Change the second OpenSubKey parameter to false, you can check in Registry Editor the permission of the key.

    using (RegistryKey serviceKey = remoteHklm.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full", false))
    

    这篇关于C# 使用 Windows 10 访问远程注册表不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆