' Here we define the RegistryKey objects for the registry hives.
'These arent all needed but I have them here as a refference for
'you to use when needed in your own apps.
Dim regClasses As RegistryKey = Registry.ClassesRoot
Dim regCurrConfig As RegistryKey = Registry.CurrentConfig
Dim regCurrUser As RegistryKey = Registry.CurrentUser
Dim regDynData As RegistryKey = Registry.DynData
Dim regLocalMachine As RegistryKey = Registry.LocalMachine
Dim regPerfData As RegistryKey = Registry.PerformanceData
Dim regUsers As RegistryKey = Registry.Users
'Define Variables for 'Write'
Dim regSoftware As RegistryKey
Dim regCompany As RegistryKey
Dim regProduct As RegistryKey
'Here we will add company and product keys under HKEY_LOCALMACHINE\
'HKEY_SOFTWARE.
'First thing is to open the key.
regSoftware = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
'Add the key, or just open it if it alread exists.
regCompany = regSoftware.CreateSubKey("JesterDev")
'Add another key for the product name.. Or again, open it of it exists.
regProduct = regCompany.CreateSubKey("JesterDevReg")
'Create the three values under the product key in the hives.
regProduct.SetValue("Path", "C:\AppPath\Bin") ' a string value
regProduct.SetValue("MajorVersion", 2) ' a numeric value
regProduct.SetValue("MinorVersion", 1) ' a numeric value
lblInfo.Text = "Values have been stored in the registry. It is advised that you delete them."
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' Delete the three values just added.
regProduct.DeleteValue("Path")
regProduct.DeleteValue("MajorVersion")
regProduct.DeleteValue("MinorVersion")
' Delete the Product key, after closing it.
regProduct.Close()
regCompany.DeleteSubKey("JesterDevReg")
' Delete the Company key, after closing it.
regCompany.Close()
regSoftware.DeleteSubKey("JesterDev")
lblInfo.Text = "Reg Keys have been deleted. Wise move."
End Sub