且构网

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

如何在c#中创建注册表

更新时间:2023-02-25 12:46:33

声明

The statement
if (key == null)


代码中的
,意味着如果您对 OpenSubKey 的调用失败,您将只执行以下代码。因此您可以保证得到该错误。它应该是


in your code, means that you will only execute the following code if your call to OpenSubKey fails. So you are guaranteed to get that error. It should be

if (key != null)



您还应该调查为什么您对 OpenSubKey 的调用失败。


您的错误是按设计:以下条件

Your error is by design: the following condition
Quote:

if(key == null)

if (key == null)

保证

Quote

key.SetValue( key 为null到达LocServer,locServername);

key.SetValue("LocServer", locServername);









你错过了一步:创建 如果它尚不存在。