Vb. NET Easy Operations Registry

Source: Internet
Author: User
The registry is in the. NET Operation registry, and vs STUDIO era, is really not the same,. NET before the operation, to introduce a large number of API functions, including key value types, error types, and so on, tedious to die, and. NET, the simple degree of realization, has been basically the same as DELPHI , here's an example to experience:



Code:
------------------------------------------------------------------------------------
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 ("Change key value already exists", msgboxstyle.information, "hint")
Else
Reg. SetValue ("Test", Txtkeyvalue.text)
MsgBox ("Set success!", msgboxstyle.information, "hint")
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 ("deleted")
Else
MsgBox ("does not exist")
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




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.