如何从Registry中检索已安装的文件路径

时间:2015-07-31 07:32:07

标签: c# registry information-retrieval registrykey

我想从注册表中检索已安装软件的路径,我尝试了不同的方法,即this onethis,但我遇到了同样的错误:

  

对象引用未设置为Object的实例。

我发现Registry.LocalMachine.OpenSubKey(registry_key)返回null所以我搜索了这个问题的解决方案并找到了很多,但这些都无法解决我的问题。我想继续以下代码:

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

任何帮助都将受到高度赞赏。

1 个答案:

答案 0 :(得分:0)

也许麻烦是因为x64位机器? 试试这个:

    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);
相关问题