WISDOMBAY

in4mation ... organized

How to Access System registry in VB .NET 2003

Page 1

Article Posted by Shanaz Bin Mohamed Abdul Lathiff for www.wisdombay.com

We can add registry keys by vb.net application using the following code:

Imports System
Imports Microsoft.Win32
Public Class Form1
Inherits System.Windows.Forms.Form
Dim RegKey As RegistryKey

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
If TextBox1.Text = "" Then
MsgBox("Cannot be created")
Else
Call createregkey(TextBox1.Text)
Call value(TextBox2.Text, TextBox3.Text)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Function createregkey(ByVal text As String)
Try
If RadioButton1.Checked = True Then
RegKey = Registry.ClassesRoot.CreateSubKey(text)
ElseIf RadioButton2.Checked = True Then
RegKey = Registry.CurrentUser.CreateSubKey(text)
ElseIf RadioButton3.Checked = True Then
RegKey = Registry.LocalMachine.CreateSubKey(text)
ElseIf RadioButton4.Checked = True Then
RegKey = Registry.Users.CreateSubKey(text)
ElseIf RadioButton5.Checked = True Then
RegKey = Registry.CurrentConfig.CreateSubKey(text)
Else
MsgBox("Cannot be created")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function

Function deleteregkey(ByVal text1 As String)
Try
If RadioButton1.Checked = True Then
Registry.ClassesRoot.DeleteSubKey(text1)
ElseIf RadioButton2.Checked = True Then
Registry.CurrentUser.DeleteSubKey(text1)
ElseIf RadioButton3.Checked = True Then
Registry.LocalMachine.DeleteSubKey(text1)
ElseIf RadioButton4.Checked = True Then
Registry.Users.DeleteSubKey(text1)
ElseIf RadioButton5.Checked = True Then
Registry.CurrentConfig.DeleteSubKey(text1)
Else
MsgBox("Cannot be deleted")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function

contd ...

Google