Bob Gatto

Bob Gatto

  • NA
  • 44
  • 8.1k

How do I get the value of a registry sub key using C#

Sep 4 2022 3:29 PM

I'm trying to get the value of a registry sub-key that I know exists. The code I'm using is:

   private void button11_Click(object sender, EventArgs e)
    {
      try
      {
        RegistryKey newKey = Registry.LocalMachine;
        newKey = newKey.OpenSubKey(@"\SOFTWARE\CyberLink\PowerDVD21");
        string loc = newKey.GetValue("OpenWithMUI").ToString();
        newKey.Close();
        MessageBox.Show("Main Dir: " + loc);
      }
      catch(Exception ex)
      {
        MessageBox.Show(ex.ToString(),"ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error);
      }
    }

When I click on the button that the code is attached to, I get this:

When I did research, it looked like what I was doing was correct. So what am I doing wrong?

Thanks for the help.

 


Answers (2)