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.

8
  • 1
    Stating the obvious but have you checked the registry to see if the key really exists ?
    – gideon
    Jul 31, 2015 at 7:34
  • so with the existing code you are getting the key as null always?If so please check the registry.
    – Joseph
    Jul 31, 2015 at 7:35
  • @Joseph yes I am always getting the key null Jul 31, 2015 at 7:35
  • @gideon I have checked the registry. Jul 31, 2015 at 7:36
  • 1
    @ Itban that means there wont be an entry corresponding to your search in the registry.Please refer this link this might help you stackoverflow.com/questions/1268715/…
    – Joseph
    Jul 31, 2015 at 7:37

1 Answer 1

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);
2

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.