2

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 ?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
pharaon450
  • 493
  • 3
  • 9
  • 21
  • 3
    What the difference between the permissions of User1 and User2? – abatishchev Jun 18 '12 at 15:38
  • 1
    Has user2 ever logged onto the machines? If not then it wont have any registry entries to check as you are searching CurrentUser. – Gaz Winter Jun 18 '12 at 15:43
  • @abatishchev i cannot access to the domain to see what are the difference between the two users – pharaon450 Jun 18 '12 at 16:07
  • @GazWinter i have 4 remote computers, USER2 only logged in onto 1 of them, i should at least see one of remote registry, but no my regKey is still NULL – pharaon450 Jun 18 '12 at 16:08
  • try this to check permissions diff b/w User1 & User2 - `Accesschk "domain\user" -a *`. Download it from here - http://technet.microsoft.com/en-us/sysinternals/bb664922 – Angshuman Agarwal Jun 18 '12 at 16:18
  • Frankly I'm surprised this even works as RegConnectRegistry() (invoked internally by OpenRemoteBaseKey) is not documented as supporting HKEY_CURRENT_USER. I guess it must impersonate you on the server side and it just happens to work if your registry is already loaded at the time. As a workaround you could try opening HKEY_USERS hive and "\\SOFTWARE\\ODBC\\..." key instead where is the account SID; I don't know how robust that is, though. – Luke Jun 18 '12 at 17:32

1 Answers1

1

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.

Ben
  • 34,935
  • 6
  • 74
  • 113