C# 2008 Can't Read/Write to the Registry?

Discussion in 'C#' started by SeW800, Jun 4, 2009.

  1. SeW800

    SeW800 New Member

    Joined:
    Jun 4, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. SeW800

    SeW800 New Member

    Joined:
    Jun 4, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
    Last edited by a moderator: Jun 4, 2009

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice