Search code examples
.netvb.netinternationalizationregistrynullreferenceexception

System.NullReferenceException with registry edit in Vb.net


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.


Solution

  • 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