Search code examples
c#.netwindowswinformsremote-registry

Remote registry always null when different user


I am creating a c# windows form application that goes read registry on remote computers.

RegistryKey regKey = RegistryKey
                        .OpenRemoteBaseKey(RegistryHive.CurrentUser, pc, RegistryView.Registry64)
                        .OpenSubKey("SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources");

When i run the application from USER1 it works because my remote computers are always logged in with USER1.

Now if i run it with USER2 my regKey is always equal to NULL, no matter what.

On my remote computers, in Component Services, i allowed the service : REMOTE REGISTRY.

Any ideas please ?


Solution

  • You cannot read HKEY_CURRENT_USER via remote registry, for the simple reason that there is no "current user" from the perspective of the remote registry service.

    For example, would it be:

    • The registry key you would see if you were logged on? (but you are not!)
    • The registry key of the current logged-on user (What if there is none? What if more than one?)

    It cannot just fetch your registry hive and load it because you may not have a roaming profile. It doesn't want to create one just so you can look at the registry.

    So: HKEY_CURRENT_USER doesn't return anything for remote registry service. If you are interested in a particular user you might look under HKEY_USERS.