I\'m trying to get data from the registry of windows to my software but there is one thing i\'m having trouble with it:
if my software runs on a 64 bit system the regist
Before you do anything further, you should have a good read of the documentation of the registry redirector. It's really important that you have a clear understanding of what it does.
OK, now that you understand the registry redirector, let's look at how to tackle your problem. You have a few options. The simplest is build your program to target x86, and access HKEY_LOCAL_MACHINE\SOFTWARE\AVAST Software\Avast ProgramFolder
no matter what bitness system you run on. That way your code will always run in a 32 bit process and so always see the 32 bit view of the registry. The registry redirector will handle the mapping onto the true physical Wow6432Node
transparently.
Alternatively, if you must use AnyCPU
, and must cater for running inside a 64 bit process, you need to use the RegistryView enumeration. This allows you to read from the 32 bit view of the registry, even from a 64 bit process. But again you access HKEY_LOCAL_MACHINE\SOFTWARE\AVAST Software\Avast ProgramFolder
but ask for that key with respect to the 32 bit view of the registry.
The golden rule with the registry redirector is that you must not hard code Wow6432Node
into your paths. The documentation says it like this:
Redirected keys are mapped to physical locations under Wow6432Node. For example, HKEY_LOCAL_MACHINE\Software is redirected to HKEY_LOCAL_MACHINE\Software\Wow6432Node. However, the physical location of redirected keys should be considered reserved by the system. Applications should not access a key's physical location directly, because this location may change.
Don't be tempted to break that rule. The system provides mechanisms to read from the 32 bit view in a supported manner.
You don't state which version of the framework you're using, but if you're using 4+ then you can use Environment.Is64BitOperatingSystem to determine the bitiness of the environment and therefore look/write to the correct place.