Http://www.codeproject.com/Articles/1003177/Access-bit-HKLM-Software-Registry-by-bit-Csharp-NE
While running 32-bit Windows application to a 64-bit Windows OS, there is a registry redirection. Here, if 32-bit application tries to read a key under hklm\software, then due to Registry redirection EF Fective path becomes hklm\software\wow6432node. For example, we is running 64-bit and 32-bit application to read registry keys as hklm\software\xyz and HKLM \SOFTWARE\WOW6432NODE\XYZ.
So by default, with an input of HKLM\Software, 64-bit application would read hklm\software\xyz while Beca Use of registry redirection 32-bit application would read hklm\software\wow6432node\xyz.
In C #, to-read 64-bit hklm\software registry keys, we can use RegistryKey.OpenBaseKey
method. This method takes the arguments- RegistryHive
and RegistryView
. Here, seperate registry views is present for 32-bit and 64-bit.
Here is the sample C # code to read for AppPaths
32-bit and 64-bit applications installed on the system:
try {string AppPath = @ "Software\microsoft\windows\currentversion\app Paths"; RegistryKey rkbase = null; Rkbase = Registrykey.openbasekey (Microsoft.Win32.RegistryHive.LocalMachine, Registryview.regi STRY32); using (RegistryKey RK = rkbase. OpenSubKey (Uninstallkey)) {foreach (String skname in RK. Getsubkeynames ()) {using (RegistryKey SK = rk. OpenSubKey (Skname)) {try { if (SK. GetValue ("Path") = null) {//add this to Requir Ed list}} catch (Except Ion ex) { MessageBox.Show (ex. Message); }}} if (Environment.is64bitope Ratingsystem) {using (RegistryKey RK = Registry.LocalMachine.OpenSubKey (AppPath ) {foreach (String skname in RK). Getsubkeynames ()) {using (RegistryKey SK = rk. OpenSubKey (Skname)) {try {if (SK. GetValue ("Path") = null) {//add this T o Required List}} catch (Exception ex) {MessageBox.Show (ex. Message); } } } } } } catch (Exception ex) {MessageBox.Show (ex. Message); }
Here, was Environment.Is64BitOperatingSystem
used to check if the current system was 64-bit or not. This function was avialable with. NET Framework 4.0.
Access 64-bit hklm\software Registry by 32-bit c#.net application