C# Access 64 bit Registry

64-bitcregistry

I was wondering if it was possible to access the following registry key in C# on a 64 bit pc.

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

When accessing on a 32bit pc it works fine but on 64 it re – directs it to the native 64bit path of HKLM\SOFTWARE\Wow6432Node which has different keys. I have looked through various articles on this but can't really find a definite answer on how to access the 32bit key in a 64bit pc in C#. Thanks.

Best Answer

If you are targetting the .Net Framework version 4.0 or above then you can do this by passing the RegistryView.Registry32 value when opening the desired registry key.

If you are targetting a previous version of the .Net Framework then you need to use P/Invoke to call RegOpenKeyEx directly yourself allowing you to pass the KEY_WOW64_32KEY flag.

There is a guide here that goes into more detail:

Related Topic