C#中对注册表的操作 读写注册表方法


    '从注册表中读信息;
    ' <param name="p_KeyName">要读取的键值</param>
    ' <returns>读到的键值字符串,如果失败(如注册表尚无信息),则返回""</returns>
    Private Function ReadInfo(ByVal p_KeyName As String)
        Dim SoftwareKey As RegistryKey = Registry.LocalMachine.OpenSubKey("Software", True)
        Dim CompanyKey As RegistryKey = SoftwareKey.OpenSubKey(m_companyname)
        Dim strvalue As String = ""
        If CompanyKey Is Nothing Then
            Return ""
            Dim SoftwareNameKey As RegistryKey = CompanyKey.OpenSubKey(m_softwarename)
            If SoftwareNameKey Is Nothing Then
                Return ""
                Try
                    strvalue = SoftwareNameKey.GetValue(p_KeyName).ToString().Trim()
                Catch ex As Exception

                End Try
                If strvalue Is Nothing Then
                    strvalue = ""
                    Return strvalue
                End If
            End If
        End If
    End Function

    '将信息写入注册表
    '<param name="p_keyname">键名</param>
    '<param name="p_keyvalue">键值</param>
    Private Sub WriteInfo(ByVal p_keyname As String, ByVal p_keyvalue As String)
        Dim SoftwareKey As RegistryKey = Registry.LocalMachine.OpenSubKey("Software", True)
        Dim CompanyKey As RegistryKey = SoftwareKey.CreateSubKey(m_companyname)
        Dim SoftwareNameKey As RegistryKey = CompanyKey.CreateSubKey(m_softwarename)
        SoftwareNameKey.SetValue(p_keyname, p_keyvalue)
    End Sub

阅读更多
个人分类: VB.NET
上一篇treeview 遍历搜索 定位目标
下一篇datagrid 单击显示所在行数据事件
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭