Reading/Writing the Registry - 32-bit vs 64-bit

S

Scott McNair

I'm trying to find a way to write/read to/from HKLM\SOFTWARE\Wow6432Node
\xxx when I'm on a 64-bit machine, and to/from HKLM\SOFTWARE\xxx when on a
regular 32-bit machine. So far all the code snippets I've found write
directly to HKLM\SOFTWARE\xxx regardless of the machine architecture.

Is there a piece of code you could show me that would be able to determine
on the fly what architecture it's using, so that it accesses the proper
hive/sub-key?

Regards,
Scott
 
S

Scott McNair

Regards,
Scott

Oh, and the obligatory code-snippets:

To write:

My.Computer.Registry.LocalMachine.CreateSubKey(Key)
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\" & Key, name, value,
RegKind)

To read:

Dim objRK As RegistryKey = RegHive.OpenSubKey(Key)
Return objRK.GetValue(name)

Thanks again,
Scott
 
S

Scott McNair

Thanks again,
Scott

Oh, and one further bit of follow-up to explain why I'm doing things this
way... this registry access is running out of a DLL which is used sometimes
on a 64-bit machine, and sometimes on a 32-bit machine. Even the apps
themselves may vary as far as what architecture they're using (XYZ.exe may
run on a 32-bit machine at one location, and on a 64-bit machine at another
locale).
 
S

Scott McNair


And of course I found the solution right after posting...

On my project properties, go to the Compile tab, then choose Advanced
Compile Options... then force it to compile as 32-bit. It will read/write
from the Wow6432 section if it's on 64-bit.

The reason I'm running into this problem in the first place is that the
vast majority of the software already in place for this project was written
in VB6, and a rewrite of the code is a long way off.
 
T

Tom Dacon

Thanks for posting the solution. So many times you see a posted question,
followed shortly by a response from the original poster that says nothing
but "never mind, I found it."

Tom Dacon
Dacon Software Consulting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top