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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章