在.NET中操作
注册表,和VS STU
dio 时代,真是不可同日而语,.NET 之前的操作,要引入大量的 API
函数,含有键值类型,
错误类型等,繁琐的要死,而.NET中,实现起来的简单程度,已经和 DELPHI 基本相同了,下面通过例子体验一下:
代码: ------------------------------------------------------------------------------------ Imports Microsoft.Win32.Registry Public Class frmMain Inherits Sy
stem.Windows.Forms.Form Private Sub Button2_Click(ByVal sender As Sy
stem.Object,ByVal e As Sy
stem.EventArgs) Handles Button2.Click Me.
dispose(True) End Sub Private Sub Button1_Click(ByVal sender As Sy
stem.Object,ByVal e As Sy
stem.EventArgs) Handles Button1.Click Dim reg As Microsoft.Win32.RegistryKey reg = CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run",True) If reg.GetValue("test") <> "" Then Msg
Box("改键值已经存在",Msg
BoxStyle.
information,"
提示") Else reg.SetValue("test",txt
keyvalue.Text) Msg
Box("设置成功!","
提示") End If reg.Close() reg =
nothing End Sub Private Sub Button3_Click(ByVal sender As Sy
stem.Object,ByVal e As Sy
stem.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") Msg
Box("已
删除") Else Msg
Box("不存在") End If reg.Close() reg =
nothing End Sub Private Sub chkAutoStart_CheckedChanged(ByVal sender As Sy
stem.Object,ByVal e As Sy
stem.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 举报,一经查实,本站将立刻删除。