积极答复者
WMI远程注册表访问

问题
-
因为公司的要求,想要做一个软件信息收集工作。
想到了远程注册表获取软件一览的方式,如下:
//...... string strHost = "localhost"; //主机名 string regMain = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"; string[] subKey = { "DisplayName" }; ManagementClass mClass = new ManagementClass(@"//" + strHost + @"/root/DEFAULT:StdRegProv"); const uint HKEY_LOCAL_MACHINE = unchecked((uint)0x80000002); object[] method_args = new object[] { HKEY_LOCAL_MACHINE, regMain, null }; uint result = (uint)mClass.InvokeMethod("EnumKey", method_args); string[] sAppList = (String[])method_args[2]; //......
以上代码在X86的windows上没有问题,但是获取X64系统时,
regMain被重新定位到了
" SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
请问如何修改代码以防止系统自动重定向注册表?谢谢!
答案
-
编译的时候选择AnyCPU
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP- 已建议为答案 mazhou 2011年9月26日 10:53
- 已标记为答案 Andrew.WuModerator 2011年10月4日 9:12
-
你好,
关于这个问题, 应该是因为64位Windows系统的系统机制导致的。
32 位程序和基于 x64 的版本的 Windows 上运行的 64 位程序在不同的模式下运行,并在注册表中使用以下各节:
- 本机模式 64 位程序运行在纯模式和访问键和存储在以下注册表子键中的值:
HKEY_LOCAL_MACHINE\Software - 32 位程序运行在 WOW64 模式和访问键和值存储在以下注册表子项中:
HKEY_LOCAL_MACHINE\Software\WOW6432node
当安装新程序或 Windows x64 版的计算机上运行程序时,所做的 64 位程序的注册表调用访问HKEY_LOCAL_MACHINE\Software
注册表子键不重定向。WOW64 截获由 32 位程序的注册表调用到HKEY_LOCAL_MACHINE\Software,然后将它们重定向到HKEY_LOCAL_MACHINE\Software\WOW6432node子键。更多的信息,请参考:http://support.microsoft.com/kb/896459
对于这个问题的更加详尽的解释与分析,可以参考下面的几篇文章:
- http://www.cnblogs.com/mingmingruyuedlut/archive/2011/01/20/1940371.html
- http://www.cnblogs.com/mingmingruyuedlut/archive/2011/01/21/1941225.html
- http://blog.csdn.net/everettjf/article/details/6617092
希望上面的信息对你有所帮助。
Andrew Wu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Andrew.WuModerator 2011年10月4日 9:12
- 本机模式 64 位程序运行在纯模式和访问键和存储在以下注册表子键中的值:
全部回复
-
编译的时候选择AnyCPU
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP- 已建议为答案 mazhou 2011年9月26日 10:53
- 已标记为答案 Andrew.WuModerator 2011年10月4日 9:12
-
你好,
关于这个问题, 应该是因为64位Windows系统的系统机制导致的。
32 位程序和基于 x64 的版本的 Windows 上运行的 64 位程序在不同的模式下运行,并在注册表中使用以下各节:
- 本机模式 64 位程序运行在纯模式和访问键和存储在以下注册表子键中的值:
HKEY_LOCAL_MACHINE\Software - 32 位程序运行在 WOW64 模式和访问键和值存储在以下注册表子项中:
HKEY_LOCAL_MACHINE\Software\WOW6432node
当安装新程序或 Windows x64 版的计算机上运行程序时,所做的 64 位程序的注册表调用访问HKEY_LOCAL_MACHINE\Software
注册表子键不重定向。WOW64 截获由 32 位程序的注册表调用到HKEY_LOCAL_MACHINE\Software,然后将它们重定向到HKEY_LOCAL_MACHINE\Software\WOW6432node子键。更多的信息,请参考:http://support.microsoft.com/kb/896459
对于这个问题的更加详尽的解释与分析,可以参考下面的几篇文章:
- http://www.cnblogs.com/mingmingruyuedlut/archive/2011/01/20/1940371.html
- http://www.cnblogs.com/mingmingruyuedlut/archive/2011/01/21/1941225.html
- http://blog.csdn.net/everettjf/article/details/6617092
希望上面的信息对你有所帮助。
Andrew Wu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Andrew.WuModerator 2011年10月4日 9:12
- 本机模式 64 位程序运行在纯模式和访问键和存储在以下注册表子键中的值:
-
你好,
请问这个问题现在是否仍然存在,有什么进展吗?
Andrew Wu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.