Friday, April 12, 2013

[VB.NET] How to save data to the registry.

Today I will show you how to sava data to your registry. I will show you the following things.

- Check if a registry key value exists.
- Create sub keys and add values to them.




 Checking if a registry key is set

If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Drivers", "Hash", Nothing) Is Nothing Then
'Your Code Here
End If

Be sure to change the "HKEY_CURRENT_USER\Drivers" and "Hash" to whatever you want.

Creating a new sub key

To create a subkey all you have to do is this.

My.Computer.Registry.CurrentUser.CreateSubKey("Hash") 

Change the "Hash" to whatever you want

Adding a value to your new sub key

Dim Hash as String = "yourhashkeyvalue"
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Drivers", "Hash", Hash)

So this code will input the value of Hash ("yourhashkeyvalue") and input that into the has subkey.


If you are looking for a good registry cleaner then be sure to check out this site.


No comments:

Post a Comment