微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

VB.NET轻松操作注册表

在.NET中操作注册表,和VS STUdio 时代,真是不可同日而语,.NET 之前的操作,要引入大量的 API 函数,含有键值类型,错误类型等,繁琐的要死,而.NET中,实现起来的简单程度,已经和 DELPHI 基本相同了,下面通过例子体验一下: 代码: ------------------------------------------------------------------------------------ Imports Microsoft.Win32.Registry Public Class frmMain Inherits System.Windows.Forms.Form Private Sub Button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button2.Click Me.dispose(True) End Sub Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click Dim reg As Microsoft.Win32.RegistryKey reg = CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run",True) If reg.GetValue("test") <> "" Then MsgBox("改键值已经存在",MsgBoxStyle.information,"提示") Else reg.SetValue("test",txtkeyvalue.Text) MsgBox("设置成功!","提示") End If reg.Close() reg = nothing End Sub Private Sub Button3_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button3.Click Dim reg As Microsoft.Win32.RegistryKey reg = CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run",True) If reg.GetValue("test") <> "" Then reg.DeleteValue("test") MsgBox("已删除") Else MsgBox("不存在") End If reg.Close() reg = nothing End Sub Private Sub chkAutoStart_CheckedChanged(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles chkAutoStart.CheckedChanged Dim regKey As Microsoft.Win32.RegistryKey regKey = CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run",True) If chkAutoStart.Checked Then If regKey.GetValue("sjcatsoft") = "" Then regKey.SetValue("sjcatsoft",Application.ExecutablePath) End If Else If regKey.GetValue("sjcatsoft") <> "" Then regKey.DeleteValue("sjcatsoft") End If End If regKey.Close() regKey = nothing End Sub End Class

原文地址:https://www.jb51.cc/vb/258349.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐