且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

vb.net 2010 - 从注册表读取不起作用 - win 7

更新时间:2023-08-22 22:49:22

好吧,我已经使用为 x86 编译的示例应用程序尝试了您的代码,但正如预期的那样,它失败并出现空值异常.

Well, I have tried your code with a sample application compiled for x86 and, as expected, it fails with a null value exception.

我假设您正在为 x86 模式构建应用程序并在 64 位环境中运行.
当然,如果不是这样,请告诉我,我会删除此答案.

I assume you are building an application for x86 mode and running in a 64bit environment.
Of course, if this is not the case, let me know and I will delete this answer.

在上述情况下,对 LocalMachine.Software 注册表路径中的读/写调用将被操作系统自动更改为在 Software\Wow6432Node 子项中读/写,因此,您的代码无法找到您的手动插入的密钥(SOFTWARE\PTSClient").
此代码将从 Registry.LocalMachine.OpenSubKey("SOFTWARE\PTSClient") 返回一个空值,导致无法获取 ConfigDB 值.

In the situation outlined above, the calls to read/write in the LocalMachine.Software registry path will be automatically changed by the Operating System to read/write in the Software\Wow6432Node subkey and thus, your code is unable to find your manually inserted key ("SOFTWARE\PTSClient").
This code will give a null value as return from Registry.LocalMachine.OpenSubKey("SOFTWARE\PTSClient") leading to the failure to get the ConfigDB value.

您需要将您的键/值添加到 Software\Wow6432Node 路径或为 AnyCPU 模式编译您的应用程序或让您的代码将值写入寄存器(它将被重定向到 Wow6432Node).

You need to add your keys/values to the Software\Wow6432Node path or compile your application for AnyCPU mode or let your code write the value to the register (it will be redirected to the Wow6432Node).