Hi,
I have a basic c#.net application that under certain circumstances need to impersonate another user and access their registry hive.
I have the impersonation and profile loading working fine using the following sequence:
(PInvoke) LogonUser
(PInvoke) LoadUserProfile
(.Net) WindowsIdentity.Impersonat
e()
I have a PROFILEINFO struct with a valid hProfile handle from the LoadUserProfile call. The documentation stated that this is a key handle to the user's registry hive.
Now obviously I could continue using revolting PInvoke calls to read and manipulate the registry using this handle, BUT..
What I really need is to be able to use the Microsoft.Win32 .net classes to do the manipulation. This is because I have to call a sealed .net assembly to do some work for me and IT needs a RegistryKey class.
So.. is there a way to get from my IntPtr registry 'handle' to a RegistryKey, or is there any other way to access the impersonated users registry hive using the .net classes?
Obviously I've tried just accessing Registry.CurrentUser after impersonation but I believe this still corresponds to the user under which the process started and so I am denied access.
Your help is appreciated!
Start Free Trial