vb.net检查注册表子项值是否存在
我有一个winform,它可以将注册数据保存到“Ddoe”下的注册表中-但是我需要检查之前是否设置(创建)了该值,我尝试这样做:vb.net检查注册表子项值是否存在,vb.net,visual-studio-2013,Vb.net,Visual Studio 2013,我有一个winform,它可以将注册数据保存到“Ddoe”下的注册表中-但是我需要检查之前是否设置(创建)了该值,我尝试这样做: If (Microsoft.Win32.Registry.LocalMachine.OpenSubKey("HKEY_CURRENT_USER\Software\FCRA\Assignment").GetValue("Ddoe") Is Nothing Then 'doesnt exist else 'exists end if 然而,这并不正常 我收到一个错误 A
If (Microsoft.Win32.Registry.LocalMachine.OpenSubKey("HKEY_CURRENT_USER\Software\FCRA\Assignment").GetValue("Ddoe") Is Nothing Then
'doesnt exist
else
'exists
end if
然而,这并不正常
我收到一个错误
An unhandled exception of type 'System.NullReferenceException' occurred in #appname
它在if语句行显示此错误
是否有更好的方法来检查此注册表项是否存在,或者我是否完全错了我认为问题在于“HKEY\U CURRENT\U USER\Software\FCRA\Assignment”不存在,因此
OpenSubKey
返回Nothing
。不能对Nothing
值使用任何方法。试试这个:
If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\FCRA\Assignment",
"Ddoe", Nothing) Is Nothing Then
'value does not exist
End If
摘自这里: