C#讀取註冊表,獲取本機安裝的軟件清單

應一個網友的需求,寫了下面的,獲取本機安裝的軟件的清單,希望對有需要的人,有幫助吧

using Microsoft.Win32;

using (RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall", false))
{
    if (key != null)
    {
        foreach (string keyName in key.GetSubKeyNames())
        {
            using (RegistryKey key2 = key.OpenSubKey(keyName, false))
            {
                if (key2 != null)
                {
                    string softwareName = key2.GetValue("DisplayName", "").ToString();
                    string installLocation = key2.GetValue("InstallLocation", "").ToString();
                    if (!string.IsNullOrEmpty(installLocation))
                    {
                        this.textBox1.AppendText(string.Format("軟件名:{0} -- 安裝路徑:{1}\r\n", softwareName, installLocation));
                    }
                }
            }
        }
    }
}

 

將取得的結果,放入 textBox1 中顯示,每行一個。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章