Checking a key in the Registry?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gsb58@hotmail.com

    #1

    Checking a key in the Registry?

    Hi!

    I have a little problem with the registry function. The function is
    supposed to check the registry as the main form is activated. If there
    is a key it should not write to the registry, as it does.

    Can anybody see what I'm doing wrong?

    Private Sub WriteToRegistry ()
    Dim regKey As RegistryKey = Nothing
    Dim regValue As String
    Try
    regValue = "Software\\MyAp p"
    regKey = Registry.Curren tUser.CreateSub Key(regValue)
    regKey.SetValue ("RunOnce", "1")
    regKey.SetValue ("Date", Now)
    regKey.SetValue ("CopyRight" , "©GSB")
    regKey.SetValue ("UserAccepted" , "Miss Piggy")
    regKey.Close()
    Catch ex As Exception
    MessageBox.Show (ex.Message, "Write_to_Regis try",
    MessageBoxButto ns.OK, MessageBoxIcon. Error)
    End Try
    End Sub

    Public Function CheckRegistryKe y() As Boolean
    Dim regVersjon As RegistryKey = Nothing
    Dim keyValue As String
    Dim bExists As Boolean = False

    Try
    keyValue = "Software\\MyAp p\\UserAccepted \\Miss Piggy"
    regVersjon = Registry.Curren tUser.OpenSubKe y(keyValue,
    False)
    If (Not regVersjon Is Nothing) Then
    bExists = True
    ElseIf (regVersjon Is Nothing) Then
    bExists = False
    WriteToRegistry ()
    End If
    Catch ex As Exception
    MessageBox.Show (ex.Message, "Check_Registry _Key",
    MessageBoxButto ns.OK, MessageBoxIcon. Information)
    Finally
    If (Not regVersjon Is Nothing) Then
    regVersjon.Clos e()
    End If
    End Try
    Return bExists
    End Function

    Private Sub frmMain_Activat ed(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles MyBase.Activate d
    Static IsActivated As Boolean
    Try
    If Not IsActivated Then
    IsActivated = True
    CheckRegistryKe y()
    End If
    Catch ex As Exception
    MessageBox.Show (ex.Message, "MAIN_ACTIVATED ",
    MessageBoxButto ns.OK, MessageBoxIcon. Information)
    End Try
    End Sub

    Hope the code is readable.

    Me.Name

Working...