Access 64-bit HKLM\Software Registry by 32-bit C#.NET Application
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Access 64-bit HKLM\Software Registry by 32-bit C#.NET Application,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2163字,纯文字阅读大概需要4分钟。
内容图文
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 RegistryKey.OpenBaseKey
method. This method takes two arguments- RegistryHive
and RegistryView
. Here, seperate registry views are present for 32-bit and 64-bit.
Here is the sample C# code to read AppPaths
for 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.Is64BitOperatingSystem
is used to check if the current system is 64-bit or not. This function is avialable with .NET Framework 4.0.
原文:http://www.cnblogs.com/zeroone/p/4604164.html
内容总结
以上是互联网集市为您收集整理的Access 64-bit HKLM\Software Registry by 32-bit C#.NET Application全部内容,希望文章能够帮你解决Access 64-bit HKLM\Software Registry by 32-bit C#.NET Application所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。