如何从C#中获取注册表的安装位置? [英] How to get install location of from registry in C#?

查看:295
本文介绍了如何从C#中获取注册表的安装位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

i想要在我的应用程序中获取所有产品的安装位置,为此我使用注册表类并使用下面的字符串值

SOFTWARE \\ theMicrosoft \\\\ nindows \\ CurrentVersion \\ unInall



SOFTWARE \\Wow6432Node\\ Microsoft \\ Windows \\ CurrentVersion \\ UnInstall64位版本。

但它并没有给我所有产品的详细信息,例如

notepad ++在注册表编辑器中的上述路径中可用但是使用我的代码它没有显示记事本的值。



我尝试了什么:



以下是我的代码



Hi all
i want to fetch install location of all products in my app so for that purpose i am using registry class and using below string value for it
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\UnInstall"
and
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\UnInstall" for 64 bit version.
but it is not giving me details of all products for example
notepad ++ available in above path in registry editor but using my code it is not displaying the values for notepad.

What I have tried:

below is my code

<pre>  StreamWriter sw = new StreamWriter(@"D:\localmachineProducts64.txt", true);
            using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
            {
                foreach (string skName in rk.GetSubKeyNames())
                {
                    using (RegistryKey sk = rk.OpenSubKey(skName))
                    {
                        try
                        {
                            sw.Write(sk.GetValue("DisplayName") + "\t" + sk.GetValue("InstallLocation"));
                            sw.Write(sw.NewLine);
                            count++;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
                sw.Write("Total count  :=" + count);
            }
            sw.Close();

推荐答案

你犯的是最严重的错误。您确定所需的值是否在卸载密钥下的每个密钥中。它不是。



无法获得列出的每个应用程序的安装位置。



此外,不是安装的每个应用程序甚至都显示在卸载密钥下!
You're making the most egregious of mistakes. Your ASSUMING that the value you want is in every one of the keys under the Uninstall key. It's not.

It's impossible to get the installed location of every application listed.

Also, not every application that's installed even shows up under the Uninstall key!


这篇关于如何从C#中获取注册表的安装位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆