if key exists

Talk2Tom11

Well-known member
Joined
Feb 22, 2004
Messages
144
Location
Westchester, NY
what I want to do is write an if statement to see if a registry key exists... if it does... I want one form to open, if it doesnt then I want the other form to open... my problem is that form2 in my code opens no matter what, if the key exists of not. I have posted the code below... please post if you know what I have done wrong.

Code:
MyKey = Registry.CurrentUser.OpenSubKey("User", False)
        If (MyKey Is Nothing) Then
            Dim f2 As New Form2
            f2.ShowDialog()
        Else
            Dim f3 As New Form3
            f3.ShowDialog()
 
Code:
Dim MyKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("User", False) 
If Not (MyKey Is Nothing) Then 
 MessageBox.Show("The Key is there") 
Else 
 MessageBox.Show("The Key is not there") 
End If

This code returns the second MessageBox with the text "The Key is not there" - in fact, I do not have that key :D
 
Back
Top