Search code examples
c#registryremote-access

C# Access Remote Registry with Windows 10 not work


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: Requested registry access is not allowed.

  • The user with i connect, is in the Administrators Group
  • The Service "RemoteRegistry" is set to Startup type "Manual"

Code example

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";
        }
    }
}

Solution

  • 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))