簡體   English   中英

C#在Windows上,如何獲取已安裝程序目錄的列表

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

因此,我找到了從此處獲取已安裝程序列表的解決方案。 在系統中獲取已安裝的應用程序

但是我想知道是否可以獲取每個目錄的安裝目錄嗎? 我需要它,因為我需要找到該程序的所有可執行文件。

任何建議,將不勝感激。

您需要從“ 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);

本示例將DisplayName鍵值與您的輸入名稱進行比較,如果找到該值,則返回InstallLocation鍵值。

此致

蒂亞古·拉詹德蘭(Thiyagu Rajendran)

**如果有幫助,請標記為答復,否則為不標記。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM