Question UpDownNumeric Value to RegKey

solignis

New member
Joined
Jun 7, 2010
Messages
3
Programming Experience
Beginner
Hello everyone this is my first post so forgive me for posting here if this is the wrong place.

I am trying to write a control interface for a backup script I am using. I got everything to work so far except for the UpDownNumeric controls I use to select values for timeouts and port numbers for the backup and emailer functions.

All of the information gathered from the form is written to registry keys in HKLM\Solignis

For whatever reason and this is my problem, when I set the value for the UpDownNumeric the first time they work just like they should and create a regkey called SMTPPortNumber when I click the "Generate Config" Button. But if I modify the value of the UpDownNumeric and click "Generate Config" again they do not change in the registry.

If I change any of the values that are not UpDownNumeric objects they update just fine when I click the button a second time.

I am storing the value of SMTPPortNumber as an Integer = STMPPortNumber.Value

Any help with this would greatly appreciated.

Oh yeah I using VB.Net 2008 Express
 
Welcome to the forums!

Have you tried running in debug and making sure the value that you expect to be there, is actually there? It would help to see the code that you use to update the registry.
 
Oddly enough about an hour after I posted this I figured out my problem out of pure luck. The only problem is I don't understand why it worked.

I don't the code at the moment cuz I posting at home the code is at my work.

The jist of it is this.

This was the original code.

VB.NET:
Private Sub GenerateConfiguration_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GenerateConfiguration.Click

Dim intSMTPPortNumber as Integer = SMTPPortNumber.Value

Dim RootKey As RegistryKey = Registry.LocalMachine.OpenSubKey("Software", True)
        Dim SubKey As RegistryKey = RootKey.CreateSubKey("Solignis")
        Dim SubKeySolignis As RegistryKey = RootKey.OpenSubKey("Software\Solignis")

SubKey.SetValue("SMTPPortNumber", intSMTPPortNumber)

And this is the code that worked.

VB.NET:
Private Sub GenerateConfiguration_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GenerateConfiguration.Click

Dim intSMTPPortNumber as Integer

Dim RootKey As RegistryKey = Registry.LocalMachine.OpenSubKey("Software", True)
        Dim SubKey As RegistryKey = RootKey.CreateSubKey("Solignis")
        Dim SubKeySolignis As RegistryKey = RootKey.OpenSubKey("Software\Solignis")

intSMTPPortNumber = SMTPPortNumber.Value

SubKey.SetValue("SMTPPortNumber", intSMTPPortNumber)

Why does the old code not update the reg key when the button is pressed but the newer code does?
 
There is no difference between how those two codes work.

Remember to close any RegistryKey object you may open or create. RegistryKey.Close Method (Microsoft.Win32) In addition to cleaning up (disposing), this also write changes.
 
Back
Top