在 vb.net 的注册表中写入 sbkey
我使用以下代码打开子项,然后在注册表中写入子项
Private Sub RegSubKeyCreates(ByVal sKeyPath As String)
Dim RegKey As RegistryKey
Dim SubKeyParam() As String = Nothing
SubKeyParam = Split(sKeyPath, "\")
RegKey = Registry.CurrentUser.OpenSubKey(SubKeyParam(0), True).OpenSubKey(SubKeyParam(1), True)
RegKey.CreateSubKey(SubKeyParam(0)).CreateSubKey(SubKeyParam(1))
End Sub
当我尝试创建子项时,出现错误
System.NullReferenceException 未将对象引用设置为对象的实例
我无法理解发生了什么。有人可以在这方面帮助我吗?
I'm using the following code to open and then write a subkey in the registry
Private Sub RegSubKeyCreates(ByVal sKeyPath As String)
Dim RegKey As RegistryKey
Dim SubKeyParam() As String = Nothing
SubKeyParam = Split(sKeyPath, "\")
RegKey = Registry.CurrentUser.OpenSubKey(SubKeyParam(0), True).OpenSubKey(SubKeyParam(1), True)
RegKey.CreateSubKey(SubKeyParam(0)).CreateSubKey(SubKeyParam(1))
End Sub
When I'm trying to create the subkey I'm geting the error
System.NullReferenceException Object reference not set to an instance of an object
I can't understand what is going on. Is there some one to assist me on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
非常感谢任何试图发送答复的人。
但我自己找到了解决方案。
所以我把它放在这里以防其他人想看。
解决方案是使用注册表 Hive 的心态。
需要明白的是,子键是一一创建的,只有在我们打开注册表到最后一个存在的子键之后。
新的子键不需要像这样在“subkey”之前或之后有任何字符
请看代码。
领先的潜艇是:
Thank you very much for any one trying to send an answer.
But i found the solution my self.
So i put it here in case that someone else want to see it.
The solution is in the mentality of working with registry Hive.
Needs to understand that the sub keys creates one by one, only after we have open the registry to the last existent sub key.
The new sub key don't need to have any character before or after "subkey" like that
please look at the code.
And the sub which leads one this is: