VB.NET操作註冊表

    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

 

發佈了29 篇原創文章 · 獲贊 15 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章