我正在尝试查看是否存在注册表项。如果确实如此,我会做的事情,如果没有,我会做其他事情。我尝试过不同的东西,但到目前为止还没有用过。
我试过了:
If My.Computer.Registry.CurrentUser.GetValue("MySubKey", True) Is Nothing Then
另外,我试图看看regKey
var是否一无所获。还有一些我不记得的了。
有什么想法吗?
感谢
答案 0 :(得分:2)
要检查注册表项是否存在,您可以使用此...
'Obtain an instance of RegistryKey for the CurrentUser registry root.
Dim rkCurrentUser As RegistryKey = Registry.CurrentUser
' Obtain the key (read-only) and display it.
If rkCurrentUser IsNot Nothing Then
Dim rkTest As RegistryKey = rkCurrentUser.OpenSubKey("MySubKey")
'Check and make sure we have something...
If rkTest IsNot Nothing Then
'You have something then...
rkTest.Close 'Close it, this is important...
Else
'You do not have anything...
End If
rkCurrentUser.Close 'Close this after you are done...
Else
'Failed to get instance of registry for the current user...
End If
还有其他方法,但请告诉我这对你有什么影响......