[COLOR="Blue"]Private Sub[/COLOR] Button1_Click([COLOR="#0000ff"]ByVal[/COLOR] sender [COLOR="#0000ff"]As[/COLOR] System.Object, [COLOR="#0000ff"]ByVal[/COLOR] e [COLOR="#0000ff"]As[/COLOR] System.EventArgs) [COLOR="#0000ff"]Handles[/COLOR] Button1.Click
SetKey([COLOR="Red"]"Software\TestApp"[/COLOR],[COLOR="#ff0000"] "Color"[/COLOR], [COLOR="#ff0000"]"Color.Red"[/COLOR])
SetKey([COLOR="#ff0000"]"Software\TestApp"[/COLOR], [COLOR="#ff0000"]"Font"[/COLOR], [COLOR="#ff0000"]"Times New Roman"[/COLOR])
MessageBox.Show(ReadKey([COLOR="#ff0000"]"Software\TestApp"[/COLOR], [COLOR="#ff0000"]"Font"[/COLOR]))
MessageBox.Show(ReadKey([COLOR="#ff0000"]"Software\TestApp"[/COLOR], [COLOR="#ff0000"]"Color"[/COLOR]))
[COLOR="Blue"]End Sub[/COLOR]
[COLOR="#0000ff"]Public Shared Function[/COLOR] ReadKey([COLOR="#0000ff"]ByVal[/COLOR] Key [COLOR="#0000ff"]As[/COLOR] [COLOR="#0000ff"]String[/COLOR], [COLOR="Blue"]ByVal[/COLOR] SubKey [COLOR="#0000ff"]As String[/COLOR]) [COLOR="#0000ff"]As String[/COLOR]
Dim regKey As Microsoft.Win32.RegistryKey
Dim ver As String = String.Empty
[COLOR="#0000ff"]Try[/COLOR]
regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(Key)
ver = regKey.GetValue(SubKey)
regKey.Close()
[COLOR="#0000ff"]Catch [/COLOR]ex [COLOR="#0000ff"]As[/COLOR] Exception
[COLOR="#0000ff"]Return False[/COLOR]
[COLOR="#0000ff"] End Try[/COLOR]
Return ver
[COLOR="#0000ff"]End Function[/COLOR]
[COLOR="#0000ff"]Public Shared Function[/COLOR] SetKey([COLOR="#0000ff"]ByVal[/COLOR] Key [COLOR="#0000ff"]As String[/COLOR], [COLOR="#0000ff"]ByVal [/COLOR]SubKey [COLOR="#0000ff"]As String[/COLOR], [COLOR="#0000ff"]ByVal[/COLOR] Value [COLOR="#0000ff"]As String[/COLOR]) [COLOR="#0000ff"]As Boolean[/COLOR]
Dim regKey As Microsoft.Win32.RegistryKey
[COLOR="Blue"] Try[/COLOR]
regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(Key, True)
regKey.SetValue(SubKey, Value)
regKey.Close()
[COLOR="Blue"] Return True[/COLOR]
[COLOR="#0000ff"] Catch[/COLOR] ex As Exception
[COLOR="#0000ff"] Return False[/COLOR]
[COLOR="#0000ff"] End Try[/COLOR]
[COLOR="#0000ff"] End Function[/COLOR]