32位程序如何访问64位的注册表
来源:互联网 发布:2017盒子免费视频软件 编辑:程序博客网 时间:2024/04/30 05:31
64位OS中,从32位Nunit调用32位DLL中的方法运行,如何访问64位的注册表项?
(也即关闭注册表转向功能。)
如读取HKEY_LOCAL_MACHINE/Software/Microsoft子项的value,而非 HKEY_LOCAL_MACHINE/Software/Wow6432Node/Microsoft子项的value。
我在网上,找到一些这方面的资料: http://www.cnblogs.com/FlyingBread/archive/2007/01/21/624291.aspx
http://msdn2.microsoft.com/en-us/library/aa365744.aspx
然后试着编码,如下,运行,结果是失败,无法打开HKEY_LOCAL_MACHINE/Software/Microsoft/Updates:
[Test]
public void test()
{
bool update = false;
IntPtr ptr = new IntPtr(1);
Wow64DisableWow64FsRedirection(ref ptr);
RegistryKey softKey = Registry.LocalMachine;
RegistryKey updateKey = softKey.OpenSubKey(@ "Software/Microsoft/Updates ");
// if the key is null
if (updateKey != null)
{
update = true;
}
Wow64RevertWow64FsRedirection(ptr);
Assert.IsTrue(update);
}
可有高手来指教一下?本人因为分数太少,就只能给20分了,见谅!!!
用RegOpenKeyEx试试看。
许查了资料,解决了这个问题。核心代码如下
public string Get() {
try
{
//the registry handle we get from regopenkeyex.
UIntPtr pHKey = new UIntPtr();
//result string
StringBuilder result = new StringBuilder();
//NOTE!!!!!!!!!!!!! This code should be improved
uint resultSize = 1024;
uint lpType = 0;
//Disble redirection
IntPtr oldWOW64State = new IntPtr();
if (Win32Encap.Win32Encap.Wow64DisableWow64FsRedirection(ref oldWOW64State))
{
//get the key handle
CrossWOW64RegVisitor.Win32Encap.Win32Encap.RegOpenKeyEx((UIntPtr)this.BaseRoot,
this.KeyPath,
0, (int)this.SAM | (int)(SAM.KEY_QUERY_VALUE),
ref pHKey);
//Disable reflection
Win32Encap.Win32Encap.RegDisableReflectionKey(pHKey);
//Get value
CrossWOW64RegVisitor.Win32Encap.Win32Encap.RegQueryValueEx(pHKey, this.ValueName, 0, out lpType, result, ref resultSize);
//Enable reflection
Win32Encap.Win32Encap.RegEnableReflectionKey(pHKey);
}
Win32Encap.Win32Encap.Wow64RevertWow64FsRedirection(oldWOW64State);
return result.ToString();
}
//if caught, there must some API not available, just return the normal value
catch (Exception ex) {
string fullKeyPath = this.BaseRoot.ToString() + "//" + this.KeyPath;
return Registry.GetValue(fullKeyPath, this.ValueName, "").ToString();
}
}
- 32位程序如何访问64位的注册表
- 32位程序如何访问64位的注册表
- C# 32位程序访问64位系统注册表
- C# 32位程序访问64位系统注册表
- C# 32位程序访问64位系统注册表
- C# 32位程序访问64位系统注册表
- Tip - 注意:32位程序访问64位系统上的Windows注册表
- 32位QT程序读取64位系统的注册表中的64位安装软件
- Win7 64位注册表与32位注册表的区别
- Win7 64位注册表与32位注册表的区别
- 如何查看32位程序在64位系统中的注册表项
- C# 32位程序与64位程序读/写注册表的区别
- C# 32位程序与64位程序读\写注册表的区别
- C# 32位程序与64位程序读\写注册表的区别
- C#32位程序与64位程序读\写注册表的区别
- C# 32位/64位程序读写注册表之差异
- 64位Windows中32位程序注册表位置的非一般处理
- *c#在64位上编写32位程序时注册表重定向的问题解决办法**
- Java 读取xml文件内容程序小结
- doubanclaim4c142e78270ee279
- winhtmleditor 控件(CS模式下的HTML编辑软件)
- return 和每个人都比前一个大5岁
- 传智播客Spring视频教程学习笔记11
- 32位程序如何访问64位的注册表
- 终于找到可以在win32 sdk下打开文件选择对话框的方法。
- c#中virtural, new, override
- php提示错误:Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO)
- linux小程序
- 仙剑,我的回忆
- php日历类
- arm汇编语言调用C函数之参数传递
- 比较 Windows XP Professional 多语言选项