Click to See Complete Forum and Search --> : Read 64-bit registry with 32-bit app
alekkh
July 2nd, 2008, 03:27 AM
Please help.
This is classic problem: I want to read Vista ProductId in my app.
The problem is my .NET application is 32-bit and Vista is 64-bit.
I can't believe that it is impossible to do, but I couldn't so far, as
LM = Registry::LocalMachine->OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\");
LMS = Convert::ToString(LM->GetValue("ProductId"));
returns NULL...
Thank you.
luweewu
August 18th, 2008, 09:00 PM
Hi alekh. I saw your question and I thought I'd help out.
I've had success reading 64-bit Registry values from a 32-bit application. The trick is to use RegOpenKeyEx() to read your values. To read anything from the 64-bit area of the Registry, you must bitwise OR KEY_WOW64_64KEY with the flag that you would normally pass into the samDesired parameter.
Follow this link: http://msdn.microsoft.com/en-us/library/ms724897.aspx for Microsft's documentation of the RegOpenKeyEx() function.
Once you have it working on a 64-bit version of Windows, if you have problems with it not working on a 32-bit version of Windows with KEY_WOW64_64KEY OR'd with the samDesired parameter, you might want to try calling GetProcAddress() first to see if it returns a pointer for "IsWow64Process". If it returns NULL, then don't OR the KEY_WOW64_64KEY flag with the samDesired parameter of the RegOpenKeyEx() call. (My code plays it safe by only ORring the flag in if it knows it's running on a 64-bit OS.)
- Rob
Rhyous
January 24th, 2011, 10:00 PM
I did extensive research on this and found that in .NET 4 it is handled easy with managed code, but prior to .NET 4, you have to load DLLIMport advapi32.dll.
Here is my research.
http://www.rhyous.com/2011/01/24/how-read-the-64-bit-registry-from-a-32-bit-application-or-vice-versa/
PeejAvery
January 25th, 2011, 01:51 PM
Welcome to the forums, Rhyous. :wave:
Please remember to make your posts relevant. This thread is 3 years old!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.