Free Games Forum
Free Games Games Forums Music Forums TV Forums

  Free Games Forum Home FORUM
HOME
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN
Rules & FAQ RULES / FAQ
REPORT SPAM

Free Games Forum: Game Technology: Visual Basic / VB:
TUT create registry keys in VB.net (vb8/vb05)

 

 


Jaymzanator
Enthusiast


Jun 21, 2006, 2:52 AM

Post #1 of 1 (276 views)
Shortcut
TUT create registry keys in VB.net (vb8/vb05) Can't Post

Intermediate: *** - Jaymzanator.com

This walkthrough demonstrates how to create an application that will browse to registry keys on the computer so users can create and delete keys, as well as how to read, get, set, and delete values.
you will need:
vb.net 2005 or later
some basic understanding of vb.net components
lets begin:


To create the main form
Select New Project in the File menu and click Windows Application.
Add a TextBox named Value to the form. In the Properties window in the lower-right corner, in the (Name) field, type Value.
Add a ListBox named History to the form. In the Properties window in the lower-right corner, in the (Name) field, type History.
Create the additional variable and add it immediately after the class declaration.

Code
Dim tempKey As Microsoft.Win32.RegistryKey

To browse registry keys in a ComboBox
Add to your form a ComboBox named selectHive, which will display the registry hives and allow you to select one. Populate it by adding the following code to the form's load event.

Code
  
selectHive.Items.Add("ClassesRoot")
selectHive.Items.Add("CurentConfig")
selectHive.Items.Add("CurrentUser")
selectHive.Items.Add("DynData")
selectHive.Items.Add("LocalMachine")
selectHive.Items.Add("PerformanceData")
selectHive.Items.Add("Users")

Attach the following code after your class declaration.

Code
Dim registryObject As Microsoft.Win32.RegistryKey = Nothing

Add the following code to the selectHive SelectedIndexChanged event.

Code
Select Case selectHive.Text  
Case "ClassesRoot"
registryObject = My.Computer.Registry.ClassesRoot
Case "CurrentConfig"
registryObject = My.Computer.Registry.CurrentConfig
Case "CurrentUser"
registryObject = My.Computer.Registry.CurrentUser
Case "DynData"
registryObject = My.Computer.Registry.DynData
Case "LocalMachine"
registryObject = My.Computer.Registry.LocalMachine
Case "PerformanceData"
registryObject = My.Computer.Registry.PerformanceData
Case "Users"
registryObject = My.Computer.Registry.Users
End Select

To read a value in a registry key
Add to the form a Button named ReadValueButton with the text "Read Value".
Add to the form a TextBox named showSubKey with the text "Enter Subkey".
Add the following code to the ReadValueButton Click event.

Code
  
tempKey = registryObject
If tempKey Is Nothing Then
MsgBox("Please select a registry hive.")
Return
End If
Value.Text = CStr(tempKey.GetValue(ShowSubKey.Text))
History.Items.Add("Read Value " & selectHive.Text & _
"\" & ShowSubKey.Text)

Test your application by entering the name of an existing subkey into the showSubKey textbox. When the ReadValueButton is clicked, the Value text box displays the value.
To set a value in a registry key
Add to the form a button named SetValueButton with the text "Set Value".
Add the following code to its Click event.

Code
  
tempKey = registryObject
If tempKey Is Nothing Then
MsgBox("Please select a registry hive.")
Return
End If
If Value.Text Is Nothing Then
MsgBox("Please enter a value.")
Return
End If
tempKey.SetValue(showSubKey.Text, Value.Text)
tempKey.Close()
History.Items.Add("Set Value " & selectHive.Text & _
"\" & showSubKey.Text)

Test your application by entering a new value for a subkey in the Value text box and then confirming that the value has been changed with the button named ReadValueButton.
To create a registry key
Add to the form a button named CreateButton with the text "Create Key".
Add the following code to its Click event.

Code
  
registryObject.CreateSubKey(showSubKey.Text)
History.Items.Add("Create Key " & selectHive.Text & _
"\" & showSubKey.Text)

Test your application by entering a new key name in the showSubKey text box and using the Registry Editor to confirm that your key has been created.
To delete a registry key
Add a button to the form named DeleteButton with the text "Delete Key".
Add the following code to its Click event.

Code
  
tempKey = registryObject
If tempKey Is Nothing Then
MsgBox("Please select a registry hive.")
Return
End If
If showSubKey.Text Is Nothing Then
MsgBox("Please enter a subkey.")
Return
End If
registryObject.DeleteSubKey(showSubKey.Text)
History.Items.Add("Delete Key " & selectHive.Text & _
"\" & showSubKey.Text)

Test your code by deleting a subkey and using the Registry Editor to confirm that the key was deleted.


(17:20) Taz:
and tazg is lol'in at you all the way from canada
(17:21) James:
lol canadians


 
 
 


Search for (options) Web Design by Web Ideas - Page loaded in: 0.10 s on (CGI/1.1)