0

i have a problem with changing a registry value. i want to set the decimal symbol from "." to "," bud everytime i debug it, it gives a System.NullReferenceException i do partly understand what it means bud i just dont know how to fix the problem.

i am using visual studio 2013.

code:

Imports System
Imports Microsoft.Win32

Module Module1

    Dim regkey As RegistryKey

    Sub Main()

        '* command's to change values in the Windows Registry

        regkey = My.Computer.Registry.CurrentUser.OpenSubKey("ControlPanel\International", True)
        regkey.SetValue("sDecimal", ",")
        regkey.Close()

    End Sub

End Module

i do need to change more registry values as well bud since i already encountered a problem that i expect to see more often i want to resolve this first. can someone explain to me what i am doing wrong?

thanks in advance.

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
F.J
  • 35
  • 10
  • possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Matt Wilko Apr 28 '15 at 08:27
  • so i used breakpoints to determen where the error occurs. it seems the variable regkey doesnt store the path to the registry key bud keeps the value "nothing" instead. bud i can't find the reason why up to this moment ( i am new to VB.net ) – F.J Apr 28 '15 at 08:56
  • In other words, the OpenSubKey call is returning null, i,e. it isn't returning the key. Does it actually exist? What is the security on it? – simon at rcl Apr 28 '15 at 13:12

1 Answers1

0

There is a space between Control and Panel in the registry key you are trying to open. your code does not have a space. Try this instead:

regkey = My.Computer.Registry.CurrentUser.OpenSubKey("Control Panel\International", True)

You may also need to run your program as administrator to change that value in the registry

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
  • it worked, thank you very much for your help. ( the devil is in the details this time ) i am currently making an installer to install the machine control interface which is required to operate the machine. the script is needed to make changes in the registry since the installer doesn't support that function very well. the default user is administrator in this case. i also need to start the interface at system startup so the user never gets to see the desktop. bud that wont be a problem. – F.J Apr 28 '15 at 09:54