0

I´m trying to get the R install path over C# but unfortunatly the Registry.LocalMachine.OpenSubKey(keyName) method returns null.

This is my code:

var keyName = @"SOFTWARE\R-core\R";

using (var key = Registry.LocalMachine.OpenSubKey(keyName))
{
   if (key != null)
   {
      var value = key.GetValue("InstallPath", 0);
      Console.WriteLine(value);
   }
   else
   {
      Console.WriteLine("No key found!");
   }

}

I manually checked if the key exists and it does.

1 Answer 1

0

Try to use

Registry.GetValue (String, String, Object)

after that you shoul cast object to your type. More information you can find on MSDN GetValue Description

6
  • I tried that already...it returns the third parameter (the default value)
    – Azeros
    Commented Jun 5, 2017 at 19:26
  • Next step. you can check full path to your key to avoid mistake with "Current_User\Local_Machine"
    – gvindar
    Commented Jun 5, 2017 at 19:35
  • What do you mean by that?
    – Azeros
    Commented Jun 5, 2017 at 19:37
  • My full path is HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R. Thats the path I used in your suggested method.
    – Azeros
    Commented Jun 5, 2017 at 19:38
  • Maybe you try to reach "HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R" instead of "HKEY_CURRENT_USER\SOFTWARE\R-core\R"
    – gvindar
    Commented Jun 5, 2017 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.