0

I am building an application in which I need to be able to gather information from the user's local Registry, and then utilize that to perform various tasks. I know where the certain registry key is located, but I can't seem to figure out how to properly extract the data. Here is the one I am trying to extract:

My ideal event would happen as follows: the utility searches for the registry value, determines it and stores it (in a var or something), then a button is displayed to the user to proceed to the next screen (I'm using WinForms). I have already set the button as "invisible" beforehand. See the attached code.

enter image description here

using (RegistryKey key = Registry.LocalMachine.OpenSubKey("HKEY_LOCAL_MACHINE\Software\Wow6432Node\DovetailGames\FSX\10.0"))
{
    if (key != null)
    {
        Object o = key.GetValue("Install_Path");

        if (o != null)
        {
            sc3op2.Visible = true; //Button is "sc3op2"
        }
    }
}

I guess my main problem is the formatting of the code to extract these values. Any help would be appreciated. Thanks.

Bender Bending
  • 729
  • 8
  • 25
will0wtree
  • 67
  • 8
  • 1
    not sure, but I think your problem is you need to remove `HKEY_LOCAL_MACHINE` from the "path" you use, since with `Regisrty.LocalMachine` you are already in HKEY_LOCAL_MACHINE – Gian Paolo Jul 31 '17 at 21:34
  • @GianPaolo That didn't work by itself but that I can see why it's wrong, I'll take it out but no luck yet. – will0wtree Jul 31 '17 at 21:36
  • The path in the code includes `10.0` category at the very end which is different from the screenshot where it is missing. Is it intentional? – Eugene Komisarenko Jul 31 '17 at 21:51
  • @EugeneKomisarenko Not at all. Fixed, but still nothing. – will0wtree Jul 31 '17 at 22:01

2 Answers2

0

Your answer might be here. Apparently, it has something to do with the virtualization of the application settings for 32 and 64-bit platforms. See the updated section If it returns null, set your build architecture to Any CPU. On my 64-bit platform, I am getting null when built using x86 or Any CPU build configuration. But it is returning the value when built using x64.

const string keyName = @"Software\Wow6432Node\DovetailGames\FSX";
var o = Registry.LocalMachine.OpenSubKey(keyName, false);
var value = o?.GetValue("Install_Path", "-");
Console.WriteLine(value);
Eugene Komisarenko
  • 1,533
  • 11
  • 25
0

First you need to remove HKEY_LOCAL_MACHINE. You need to use @ before the string.

take a look Screenshot

    using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Apple Inc.\Apple Application Support"))
        {
            if (key != null)
            {
                Object o = key.GetValue("Installdir");

                if (o != null)
                {
                  // do something
                }
            }
        }
Thiago Loureiro
  • 1,041
  • 13
  • 24