Get near VB.net (12) Registry Quick Start

Source: Internet
Author: User
Tags numeric tostring win32 knowledge base
Quick Start | Registry approaching vb.net (12) Registry QuickStart
Author: Hejianzhong VB. NET Chinese station (http://vbnetcn.126.com)
First, introduce the basic knowledge of the registry: each folder in the registry is called a key (item), and the subfolder of this folder is called the subkey (sub
, and in a subkey there is a different value Name (the value item-the top of the number), and the value item is followed by the data value (data) you want to save. And in the subkey
There is usually a default value of value Name, and I believe that the registry must be open to see clearly:
OK, let's take a look at how to write to the registry.
The easiest way to do this is to use the VB built-in function, which is exactly the same as the method used in VB6:
————————————————————————————————————————
Set Sub SaveSetting (AppName as string,section as string,key as string,setting as String)
Get Function getsetting (AppName as string,section as string,key as string,[default as String])
Delete DeleteSetting (AppName as string,[section as string=nothing],[key as string=nothing])
————————————————————————————————————————————————
But he can only write in a fixed position, write Hkey_current_user//software//vb and VBA program Setting. When we need to make
When you encrypt with the registry, you can't always write it in a place that everyone knows about, right? Also, when we want to use the registry to implement some features (such as writing the run primary key to let the program
Self-running on startup) This is more powerless. I believe everyone has seen the VB6 routine, it is very complicated. But I read a series of articles well written (on my website
---VB6 Knowledge Base is included) has seven or eight pages. In the vb.net is very simple, with the above really somewhat similar. --------(But I've been studying for a long time.
Bitter---recently someone put my article into my own name, I am very sad, also please these people self-respect, again declared in any place posted must pass my consent, and clear
Marked: "Author: Hejianzhong VB." NET Chinese station http:://vbnetcn.126.com. " The words)
I wrote a module here, just for example, when you use it, remember that you don't need to use the module like I do (should be flexible according to your needs)
Use), which is a little superfluous. I also do not intend to provide source download, because it is too simple.
First, add the control as shown in the diagram:


The text of the TextBox control is set to "", and the others are modified accordingly, in fact, you can not make up the example, as long as you understand the following content on the line:
Write the code as follows:

Imports System.ComponentModel Imports System.Drawing Imports System.WinForms public Class Form1 Inherits system.winforms . Form public Sub New () mybase.new Form1 = Me "This" is required by the Win form Designer. InitializeComponent ' Todo:add any initialization on the InitializeComponent () call End Sub ' Form overrides dispose to Clean up the component list. Overrides public Sub Dispose () mybase.dispose components. Dispose End Sub below these #Region "Windows Form Designer generated code" ' Required by the Windows Form Designer Private compo Nents as System.ComponentModel.Container private WithEvents Label2 as System.WinForms.Label private WithEvents Label1 as S Ystem. Winforms.label private WithEvents TextBox2 as System.WinForms.TextBox private WithEvents Button4 as System.WinForms.Button private WithEvents Button3 as System.WinForms.Button private WithEvents TextBox1 as System.WinForms.TextBox private WithEvents Button1 as System.WinForms.Button private WithEvents RadioButton2 as System.wiNforms.radiobutton Private WithEvents RadioButton1 as System.WinForms.RadioButton Dim WithEvents Form1 as System.WinForms.Form ' note:the following procedure is required by the Windows Form Designer ' It can be modified using the Windows Form Designer. ' Do not modify it using the ' Code Editor. Private Sub InitializeComponent () me.components = new System.ComponentModel.Container () Me.textBox1 = new System.WinForms.TextBox () Me.textBox2 = new System.WinForms.TextBox () Me.label2 = new System.WinForms.Label () Me.label1 = new System.WinForms.Label () Me.button4 = new System.WinForms.Button () Me.radiobutton1 = new System.WinForms.RadioButton () Me.button3 = new System.WinForms.Button () Me.button1 = new System.WinForms.Button () Me.radiobutton2 = New System.WinForms.RadioButton () ' @design me.trayheight = 0 ' @design Me.traylargeicon = False ' @design Me.trayautoarrange = True textbox1.location = New System.Drawing.Point (184,%) Textbox1.multiline = True Textbox1.tabind ex = 3 Textbox1.size = New SysTem. Drawing.size (144) Textbox2.location = New System.Drawing.Point (184, 128) Textbox2.multiline = True Textbox2.tabindex = 7 Textbox2.size = new System.Drawing.Size (144) label2.location = new System.Drawing.Point (in) Label2.Text = "La Bel2 "label2.size = new System.Drawing.Size (264,) Label2.tabindex = 9 Label1.location = new System.Drawing.Point (16, 18 4) Label1.Text = "current position" label1.size = new System.Drawing.Size (+) Label1.tabindex = 8 Button4.location = new System.dr Awing. Point (8, 152) Button4.size = New System.Drawing.Size (in) Button4.tabindex = 6 Button4.text = "Read Data" Radiobutton1.loca tion = new System.Drawing.Point (8, 8) Radiobutton1.text = "Write HKEY_CURRENT_USER" radiobutton1.size = new System.Drawing.Si Ze (radiobutton1.tabindex) = 0 button3.location = new System.Drawing.Point (8, 112) Button3.size = new System.drawin G.size Button3.tabindex = 5 Button3.text = "Write data" button1.location = New System.Drawing.Point (8) button1.size = New SYSTEM.DRawing. Size (Button1.tabindex) = 2 Button1.Text = "Open registry subkey (subkey)" Radiobutton2.location = New System.Drawing.Point (8, 40 Radiobutton2.text = "Write hkey_local_machine" Radiobutton2.size = New System.Drawing.Size radiobutton2.tabindex = 1 Me.Text = "Form1" me.autoscalebasesize = new System.Drawing.Size (6) me.clientsize = new System.Drawing.Size (336, 2 ) Me.Controls.Add (Label2) Me.Controls.Add (Label1) Me.Controls.Add (TextBox2) Me.Controls.Add (Button4) ME.CONTROLS.ADD (Button3) Me.Controls.Add (TextBox1) Me.Controls.Add (Button1) Me.Controls.Add (RadioButton2) ME.CONTROLS.ADD (RadioButton1) End Sub #End Region Protected Sub button4_click (ByVal sender as Object, ByVal e as System.ev Entargs) TextBox2. Text = Getval ("Numeric Entry"). ToString End Sub Protected sub Button3_Click (ByVal sender as Object, ByVal e as System.EventArgs) writeval ("Numeric Entry", TextBox2 . Text): TextBox2. Text = "Written to Registry" End Sub Protected sub Button1_Click (ByVal sender as Object, ByVal e as System.EventArgs) If Objkey =Nothing Then MsgBox ("Please select the registry root above First") Me.RadioButton1.Select () Openbasekey (Microsoft.Win32.RegistryHive.CurrentUser) Label2. Text = Objkey. ToString Exit Sub End If Newsubkey (textbox1. Text) Label2. Text = Objkey. ToString End Sub Protected sub Radiobutton2_checkedchanged (ByVal sender as Object, ByVal e as System.EventArgs) Openbaseke Y (Microsoft.Win32.RegistryHive.LocalMachine) Label2. Text = Objkey. ToString End Sub Protected sub Radiobutton1_checkedchanged (ByVal sender as Object, ByVal e as System.EventArgs) Openbaseke Y (Microsoft.Win32.RegistryHive.CurrentUser) Label2. Text = Objkey. ToString End Sub-end Class ' ####################################################################################### ########################### public Module Rwregkey ' defines a Objkey registration entry object Public Objkey as Microsoft.Win32.RegistryKey ' ___ _____________________________________________________________________________________________________________ ' Use Openremo The Tebasekey method opens a registry root project, using rgistryhive to obtain a top-level key root project public SubOpenbasekey (ByVal Basekey as Microsoft.Win32.RegistryHive) Objkey = Microsoft.Win32.RegistryKey.OpenRemoteBaseKey ( Basekey, Systeminformation.computername) end Sub ' ________________________________________________________________ __________________________________ ' enables OpenSubKey to open a specified subproject, Public sub Nextsubkey (ByVal keyname as String, ByVal Writeable as Boolean) Objkey = Objkey. Boolean value (True,false) after OpenSubKey (KeyName, writeable) specifies whether to read-write if Objkey = keytemp Then end Sub ' ____________________________ ________________________________________________________________________________ '______________________________ _________________________________________________________________________ ' If you can't find it, create a new subkey subproject Public Sub Newsubkey (ByVal keyname as String) Objkey = Objkey.createsubkey (keyname) ' Here we have created a new subkey (item) End Sub ' _______________ _____________________________________________________________________________________________________ ' writes the data that needs to be saved-------Va Luedata public Sub writeval (ByVal valname As String, ByVal Valdata as Object) Objkey. SetValue (Valname, Valdata) ' Write data----valuedata End Sub ' ____________________________________________________________ ________ ' reads the saved data public Function getval (ByVal valname as String) as Object return Objkey.getvalue (valname) End Function ' _________ ' Deletes a registry key public Sub Delkey (ByVal keyname as String) Objkey. DeleteSubKey (keyname) End Sub ' __________________________________________________________________________________ _________________________() '___________________________________________________________________________________ _________________________________ ' Deletes a data------valuedata public Sub delval (ByVal valname as String) Objkey. DeleteValue (valname) ' Deletes a value of Objkey. Close () ' Remember to turn him off after use, which is usually a good habit advocated. End Sub End Module It is not easy to see, I have seen people in the forum said, VB6 used very well why I use vb.net. and net is just net technology, our this ... irrelevant. This is a huge misunderstanding. Because the back with a net, we do not understand and alienated him, no matter what, VB. NET because object-oriented can write programs more efficiently. Why should we reject it? My series of text out later, learn vb.net people also increased a lot, I saw a netizen in the NetEase Forum said in order to install vb.net installed a afternoon, then I told him to my site immediately buttoned up. So I'm not against posting myArticle (I have been in the discussion group to promote vb.net and advertising suspicion), but you always want to say hello to me? I have no selfish motives, for everyone, but why do you want to hide my name and Web site? What's more, he openly replaced the article author with his own name (in NetEase my "VB." Net Diagram Introduction "Step by Step installation vb.net" unexpectedly was changed into "the Author: Big Head Ghost",---has been deleted by the Administrator!,). See these, my heart is a little cold. A few days ago because the speed is too slow, I applied for a high-speed website overnight, upload all the information overnight, who knows upload and strange slow, two days, spent more than 10 hours online. I hope you do not like this to hit me, this is not a question of fame and wealth, but a person at least the dignity of the Du Du.


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.