Andrew Haxalot
Andrew Haxalot

Reputation: 11

Having Trouble With VB.NET Registry Editing

I'm trying to make a simple program that will add a value to a specific part of my Windows Registry when I press a button, but it keeps adding it in the wrong place. I specified the right location of where I want the thing to be added. So, I don't know why it's doing that, but I'd like to find out how I can fix it so it will add it in the right place. This is my code so far:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim key As RegistryKey = Registry.LocalMachine
    Dim subkey As RegistryKey
    subkey = key.OpenSubKey("HKEY_CURRENT_USER\Software\Ashampoo\Ashampoo MouseTracer\legend", True)
    My.Computer.Registry.CurrentUser.SetValue("day6Value", 99999999999.999)
End Sub

It places the thing that I want to add in the HKEY_CURRENT_USER root directory, instead of HKEY_CURRENT_USER\Software\Ashampoo\Ashampoo MouseTracer\legend

Any help at all would be greatly appreciated. Thanks!

Upvotes: 0

Views: 2003

Answers (2)

origin1tech
origin1tech

Reputation: 749

C#

RegistryKey key = Registry.LocalMachine.OpenSubKey(@"HKEY_CURRENT_USER\Software\Ashampoo\Ashampoo MouseTracer\legend", true);
key.SetValue("key", "1", RegistryValueKind.String);
key.close();

VB

Dim key As RegistryKey = Registry.LocalMachine.OpenSubKey("HKEY_CURRENT_USER\Software\Ashampoo\Ashampoo           MouseTracer\legend", True)
key.SetValue("key", "1", RegistryValueKind.[String])
key.close()

Upvotes: 1

Rowan Freeman
Rowan Freeman

Reputation: 16358

From what I can tell, the problem looks to be here:

subkey = key.OpenSubKey("HKEY_CURRENT_USER\Software\Ashampoo\Ashampoo MouseTracer\legend", True)
My.Computer.Registry.CurrentUser.SetValue("day6Value", 99999999999.999)

You set the subkey but then, instead of adding to it, you add to the CurrentUser.

Try this:

subkey = key _
    .OpenSubKey("HKEY_CURRENT_USER\Software\Ashampoo\Ashampoo MouseTracer\legend", True)
subkey.CreateSubKey("day6Value")
subkey.SetValue("day6Value", 99999999999.999)

Upvotes: 1

Related Questions