0

I would like to retrieve the path of an installed software from registry, I have tried different methods i.e. this one and this too but I faced the same error:

Object reference not set to an instance of an Object.

I observed that Registry.LocalMachine.OpenSubKey(registry_key) returns null so I searched for the solution of this problem and found many, but those could not solve my issue. I want to continue with the following code:

string txt_filePath = "";

RegistryKey key = Registry.LocalMachine.OpenSubKey(@"HKEY_LOCAL_MACHINE\SOFTWARE\Bentley\AutoPIPE\V8i SELECTSeries 6 Ribbon Preview and Reporting");
object objRegisteredValue = key.GetValue("ApplicationPath");

txt_filePath = objRegisteredValue.ToString();

Any help will be highly appreciated.

Community
  • 1
  • 1
Itban Saeed
  • 1,660
  • 5
  • 25
  • 38

1 Answers1

0

Maybe trouble is because of x64-bit machine? Try this:

    var regView = Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32;
    var registry = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, regView);

    var keyPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Bentley\AutoPIPE\V8i SELECTSeries 6 Ribbon Preview and Reporting\RibbonUI.xml";
    var key = registry.OpenSubKey(keyPath);
Artem Kulikov
  • 2,250
  • 19
  • 32
  • Thanks a lot for the response but I am working on VS2008 having .NET version 3.5 , this code is not supported here. – Itban Saeed Jul 31 '15 at 07:44
  • 1
    You can find an alternative way for version 3.5 here: http://stackoverflow.com/questions/26217199/what-are-some-alternatives-to-registrykey-openbasekey-in-net-3-5 – Artem Kulikov Jul 31 '15 at 07:47