codebuilder
codebuilder

Reputation: 11

Reading the registry on a 64-bit machine

I have developed a 32-bit application (build for x86) which will later be deployed on a 64-bit machine. I have set some configuration in registry so when the application starts on a 32-bit machine there is no problem reading its value, but when deployed on a 64-bit machine I can not read the value properly as the path of the registry is changed. To make things clear, on a 32-bit machine I have the registry entry as follows.

[HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication\InstallationPath]

"folder"="C:\Program Files\MyApplication"

But when I look on a 64-bit machine, this is shifted to:

[HKEY_LOCAL_MACHINE\SOFTWARE\**Wow6432Node**\MyApplication\InstallationPath]

"folder"="C:\Program Files\MyApplication"

Inside my application I have to query the value of the installation path. The obvious thing I have done is query the value with the hardcoded string "HKLM\SOFTWARE\MyApplication\InstallationPath", but which is not valid for a 64-bit machine.

How do I overcome this problem?

Upvotes: 1

Views: 2019

Answers (3)

Alex Jasmin
Alex Jasmin

Reputation: 39496

You shouldn't have to do anything special in your code. 32-bit applications transparently access the portion of the registry under Wow6432Node.

To convince yourself of this, launch the 32-bit build of regedit.exe (available under Windows\SysWOW64) and take look around the registry.

Upvotes: 0

Leo Davidson
Leo Davidson

Reputation: 6133

Have a look at the REGSAM samDesired argument of RegOpenKeyEx and many of the other registry APIs.

The important one for you is KEY_WOW64_64KEY: "Indicates that an application on 64-bit Windows should operate on the 64-bit registry view. For more information, see Accessing an Alternate Registry View."

You can use that in a 32-bit app to force it to inspect registry keys in the "native" 64-bit areas on a 64-bit system. (You might want to check that you're running on 64-bit Windows and only pass the flag then; I'm not sure what it would do on a 32-bit machine. Pass zero for samDesired when you want the default handling.)

Upvotes: 1

Frédéric Hamidi
Frédéric Hamidi

Reputation: 262919

I don't really understand your problem: the Wow6432Node is transparent from the caller's point of view.

That means the registry key HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication\InstallationPath will be automatically mapped to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\MyApplication\InstallationPath when accessed from a 32-bit application running on a 64-bit machine.

So your code should work out of the box.

Upvotes: 1

Related Questions