'从注册表中读信息;
' <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
本文介绍了一种在Windows环境下通过Visual Basic .NET实现注册表读写的方法。文章详细展示了如何创建、打开及读取注册表键值的具体步骤,并提供了异常处理机制确保程序稳定运行。

5172

被折叠的 条评论
为什么被折叠?



