简体   繁体   English

C#在Windows上,如何获取已安装程序目录的列表

[英]C# On windows, how to get a list of installed programs' directories

So I found the solution of getting a list of installed programs from here. 因此,我找到了从此处获取已安装程序列表的解决方案。 Get installed applications in a system 在系统中获取已安装的应用程序

But I wonder if I can get the installed directory of each of them? 但是我想知道是否可以获取每个目录的安装目录吗? I need it because i would need to find all the executable files for that program. 我需要它,因为我需要找到该程序的所有可执行文件。

Any suggestions would be appreciated. 任何建议,将不胜感激。

You need to find all installed app from "HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall" Here is the sample code 您需要从“ HKLM \\ Software \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall”中找到所有已安装的应用程序,这是示例代码

private string FindByDisplayName(RegistryKey parentKey, string name)
    {
        string[] nameList = parentKey.GetSubKeyNames();
        for (int i = 0; i < nameList.Length; i++)
        {
            RegistryKey regKey =  parentKey.OpenSubKey(nameList[i]);
            try
            {
                if (regKey.GetValue("DisplayName").ToString() == name)
                {
                    return regKey.GetValue("InstallLocation").ToString();
                }
            }
            catch { }
        }
        return "";
    }

RegistryKey regKey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");
string location = FindByDisplayName(regKey, "MSN");
MessageBox.Show(location);

This example will compare the DisplayName keyvalue to your input name, if it find the value, then return the InstallLocation key value. 本示例将DisplayName键值与您的输入名称进行比较,如果找到该值,则返回InstallLocation键值。

Sincerely, 此致

Thiyagu Rajendran 蒂亚古·拉詹德兰(Thiyagu Rajendran)

**Please mark the replies as answers if they help and unmark if they don't. **如果有帮助,请标记为答复,否则为不标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM