REM 設置根節點
Private key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser
Function readKey(path, Optional ByVal value = "")
Dim subkey As Microsoft.Win32.RegistryKey
subkey = key.OpenSubKey(path, False)
If subkey Is Nothing Then
addKey(path, value) '不存在就把創建一個並把value寫進去
subkey = key.OpenSubKey(path, False)
End If
Return subkey.GetValue("") '註冊表子結點
End Function
Sub modifyKey(path, value)
Dim subkey As Microsoft.Win32.RegistryKey
subkey = key.OpenSubKey(path, True)
subkey.SetValue("", value, Microsoft.Win32.RegistryValueKind.String)
End Sub
Sub addKey(path, value)
Dim subkey As Microsoft.Win32.RegistryKey
subkey = key.CreateSubKey(path)
subkey.SetValue("", value, Microsoft.Win32.RegistryValueKind.String)
End Sub
Sub safeOpeningForm()
Dim xPath= "Software\a\x"
Dim yPath= "Software\a\y"
Dim zPath= "Software\a\z"
Dim r1 = readKey(xPath)
Dim r2 = readKey(yPath)
Dim r3 = readKey(zPath)
End Sub