加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

2哥学Vb.net--注册表操作

发布时间:2020-12-17 08:14:23 所属栏目:百科 来源:网络整理
导读:对注册表的操作:简单的增删改查 Imports Microsoft.Win32 Public Class Form1 Private RegCurrentConfig As RegistryHive = "-2147483643" Private RegClassUsers As RegistryHive = "-2147483645" Private RegLocalMachine As RegistryHive = "-2147483646

对注册表的操作:简单的增删改查

Imports Microsoft.Win32
   
Public Class Form1
    Private RegCurrentConfig As RegistryHive = "-2147483643"
    Private RegClassUsers As RegistryHive = "-2147483645"
    Private RegLocalMachine As RegistryHive = "-2147483646"
    Private RegCurrentUser As RegistryHive = "-2147483647"
    Private RegClassRoot As RegistryHive = "-2147483648"
    ''' <summary>
    ''' 操作注册表
    ''' </summary>
    ''' <param name="Hive"></param>
    ''' <param name="Key"></param>
    ''' <param name="ValueName"></param>
    ''' <param name="ErroInfo"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function RegValue(ByVal Hive As RegistryHive,ByVal Key As String,ByVal ValueName As String,Optional ByRef ErroInfo As String = "") As String
        RegValue = ""
        Dim objParentKey As RegistryKey
        Dim objSubKey As RegistryKey

        Select Case Hive
            Case RegistryHive.ClassesRoot
                objParentKey = Registry.ClassesRoot
            Case RegistryHive.CurrentConfig
                objParentKey = Registry.CurrentConfig
            Case RegistryHive.CurrentUser
                objParentKey = Registry.CurrentUser
            Case RegistryHive.LocalMachine
                objParentKey = Registry.PerformanceData
            Case RegistryHive.Users
                objParentKey = Registry.Users
        End Select

        'Create subkey
        Dim rk As RegistryKey
        rk = objParentKey.OpenSubKey("Hello",True)
        rk.CreateSubKey("MyRegistrySubKey",True)

        'Set value
        rk.SetValue("Hello","Kitty")

        'get Value
        Try
            objSubKey = objParentKey.OpenSubKey(Key)
            If IsNothing(objSubKey) = False Then
                RegValue = (objSubKey.GetValue(ValueName))
            End If
        Catch ex As Exception
            ErroInfo = ex.Message
        Finally
            If ErroInfo = "" And RegValue = "" Then
                ErroInfo = "No value"
            End If
        End Try

        'delete subkey
        rk.DeleteSubKey("xxx",False)

        rk.Close()
        Return RegValue
    End Function


    'test
    Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load
        MsgBox(RegValue(RegCurrentUser,"Control PanelColors","ActiveBorder"))
    End Sub
End Class

更加详细的信息,可以查询:http://www.lob.cn/Special/registry/Index.shtml

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读