Support Forums

Full Version: [TuToRiAl] How to Get/Edit the value of a key in the Registry (Part 2)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone, your tutorial guru, legitwaste here...

Today we are going to learn how to edit and read a registry key, extremely simple, unless you want to make it complicated for yourself lol.


WARNING: You Must Be Running the Application as an Administrator if you are using Windows Vista/7, XP Users need to use this technique
only when accessing the LOCAL_MACHINE.


Now add 2 buttons and 2 textboxes to your form so that they look like this:
[Image: 29dfpqq.png]

Now for the coding.

As usual we must import ms.win32


Code:
Imports Microsoft.Win32
Public Class Form1

Next we will edit the code of "read a value" a.k.a. Button1.

We are trying to find and then edit the value of the string, Test. As you can see the value is "SupportForumsRocks".


[Image: 2vvqbuh.png]

Lets see if we can make it work.

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = Registry.GetValue("HKEY_CURRENT_USER\Environment\", "Testing", "")
    End Sub

It works!

[Image: 2jf14b4.png]

Now for the second button a.k.a. Edit the value, in vb known as "set".

Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Registry.SetValue("HKEY_CURRENT_USER\Environment\", "Testing", TextBox2.Text, RegistryValueKind.String)
    End Sub

Now the results should be like this:

[Image: 23sdp5l.png]

Then after setting the value to HFrox,

[Image: 2ceop75.png]

[Image: rmv3hy.png]

And that is how you are able to read and edit the value of a registry key.