Write into registry

PROKA

Well-known member
Joined
Sep 3, 2003
Messages
249
Location
Bucharest
Ok so my code is :
[VB]
tempreg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\my program", True)
tempreg.setvalue("Tries", TriesString)
[/code]

in a sub which handles mybase.closing

I get this error :
Code:
An unhandled exception of type System.NullReferenceException occurred in microsoft.visualbasic.dll

Additional information: Object variable or With block variable not set.

well, if I put the number "2" instead of "TriesString" I get the same error
 
Are you sure you have the path "Software\my program" in your registry, or the key "Tries"

I do not hink there could be another error about it...
 
Is tmpreg a RegistryKey type?

Also I prefer to open each subkey individually as it makes things clearer (to me at least):

Code:
RegistryKey tempreg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software", True).CreateSubKey("my program")
            tempreg.setvalue("Tries", TriesString)
Also as you can see I use Open on the keys I know should be there and Create on the keys Im not sure of because the create will open the key if it exists, if it doesnt it will create it.
 
Back
Top