Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   C# 2008 Can't Read/Write to the Registry? (http://www.go4expert.com/forums/c-sharp-2008-read-write-registry-t17852/)

SeW800 4Jun2009 04:55

C# 2008 Can't Read/Write to the Registry?
 
I have the following code which should read/write from the registry but it seems it doesn't do anything and C# 2008 doesn't report any errors.

Here is the write sequence:

pb8.Value = (pb8.Value + 1);
RegistryKey registry = Registry.LocalMachine.CreateSubKey(@"SOF...
if (registry != null)
{
registry.SetValue("TheValue", pb8.Value);
registry.Close();
}

And here is the read sequence:

RegistryKey registry = Registry.LocalMachine.CreateSubKey(@"SOF...
if (registry != null)
{
pb8.Value = Convert.ToInt32(registry.GetValue("TheVa...
registry.Close();
}
tmrBegin.Enabled = false;

Note: pb8 is a progress bar, which I'm using to read/write the registry value into. Also, this
code is placed into two timers, so the value of pb8 is increased by 1 every second.

SeW800 4Jun2009 05:21

Re: C# 2008 Can't Read/Write to the Registry?
 
Sorry, the text in the post above didn't paste as it should.

Here is the correct (full one):

Hi,

I have the following code which should read/write from the registry but it seems it doesn't do anything and C# 2008 doesn't report any errors.

Here is the write sequence:
Code:

pb8.Value = (pb8.Value + 1);
RegistryKey registry = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\\Test");
if (registry != null)
{
registry.SetValue("RegisteredOwner", pb8.Value);
registry.Close();
}

And here is the read sequence:
Code:

RegistryKey registry = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\\Test");
if (registry != null)
{
pb8.Value = Convert.ToInt32(registry.GetValue("RegisteredOwner"));
registry.Close();
}
tmrBegin.Enabled = false;

Note: pb8 is a progress bar, which I'm using to read/write the registry value into. Also, this
code is placed into two timers, so the value of pb8 is increased by 1 every second.


All times are GMT +5.5. The time now is 15:18.