|
-
Dec 18th, 2002, 04:07 PM
#1
Thread Starter
New Member
Test if registry key exists
Anyone know of a better way of testing to see if a reg key exists? Currently I am just catching the nullreferenceexception and using that ... but I would prefer a "exists" method or the like ...
Anyway, here is what I am doing ...
Imports Microsoft.Win32
Public Class cRegistry
Public Shared Function TestForKey(ByVal Reg_Key_Path As String, _
ByVal Reg_Value As String) As Boolean
Dim s As String
Dim reg_key As RegistryKey
Dim reg_hive As RegistryHive
Try
reg_key = Registry.LocalMachine.OpenSubKey(Reg_Key_Path)
If reg_key.ValueCount = 0 Then
Return False
Else
Return True
End If
Catch nre As NullReferenceException
Return False
Catch e As Exception
Throw New Exception("The following error occured while testing the Registry Key", e)
End Try
End Function
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|