Access 64-bit HKLM\Software Registry by 32-bit C#.NET Application
2015-06-27 15:45
639 查看
http://www.codeproject.com/Articles/1003177/Access-bit-HKLM-Software-Registry-by-bit-Csharp-NE
While running 32-bit Windows application on 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 effective path becomes HKLM\Software\Wow6432Node. For example, we are 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 will read HKLM\Software\xyz while because of registry redirection 32-bit application will read HKLM\Software\Wow6432Node\xyz.
In C#, to read 64-bit HKLM\Software registry keys, we can use
Here is the sample C# code to read
Here,
While running 32-bit Windows application on 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 effective path becomes HKLM\Software\Wow6432Node. For example, we are 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 will read HKLM\Software\xyz while because of registry redirection 32-bit application will read HKLM\Software\Wow6432Node\xyz.
In C#, to read 64-bit HKLM\Software registry keys, we can use
RegistryKey.OpenBaseKeymethod. This method takes two arguments-
RegistryHiveand
RegistryView. Here, seperate registry views are present for 32-bit and 64-bit.
Here is the sample C# code to read
AppPathsfor 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.Registry32); 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 required list } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } if (Environment.Is64BitOperatingSystem) { 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 to required list } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); }
Here,
Environment.Is64BitOperatingSystemis used to check if the current system is 64-bit or not. This function is avialable with .NET Framework 4.0.
相关文章推荐
- Android按钮点击监听事件的写法
- ios 启动程序时隐藏状态栏,启动后显示状态栏
- android studio打包APK
- 【Unity3d】在编辑器中实现位操作(Bit)的编辑
- android 自定义对话框 位置
- Android项目打包成APK文件
- Android使用腾讯定位SDK显示当前地址
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
- Android ListView 自定义 Adapter
- 在Ubuntu中安装Unity 8桌面预览版
- Android 1.6-5.0源码下载地址
- Android项目打包
- Android中读取短信信息
- android 三种定位方式
- iOS7隐藏状态栏 status Bar
- iOS开发笔记(Swift)-通用App安装引导页的实现
- 【Unity3d】调整NGUI的打包工具,让NGUI打包Atlas时,自动获得图片九宫信息。
- Android使用聚合数据接口解析JSON数据显示当前地址
- 微信 oauth授权 获取用户的信息
- cocos2d-x3.6 连连看连通画线