Advertisement

05.22.2008 at 03:03AM PDT, ID: 23423764
[x]
Attachment Details

Getting Microsoft.Win32.RegistryKey from PROFILEINFO.hProfile - from PInvoke to .Net

Asked by eeriksson in .NET Framework 2.0, .NET, C# Programming Language

Tags: c# .net

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.Impersonate()

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
[+][-]05.22.2008 at 03:59AM PDT, ID: 21622595

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.25.2008 at 08:19AM PDT, ID: 21866633

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET Framework 2.0, .NET, C# Programming Language
Tags: c# .net
Sign Up Now!
Solution Provided By: graye
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.17.2008 at 05:55PM PDT, ID: 22031738

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 03:51PM PDT, ID: 22064424

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628