程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> c#獲取安裝的軟件和路徑(注冊表)

c#獲取安裝的軟件和路徑(注冊表)

編輯:C#入門知識

獲取安裝軟件和路徑,通過注冊表得到。實例代碼:

 using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SoftwareMicrosoftWindowsCurrentVersionUninstall", 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))
                                {
                                    //將信息添加到ListView控件中
                                    ListViewItem item = new ListViewItem(softwareName);
                                    item.SubItems.Add(installLocation);
                                    listView1.Items.Add(item);
                                }
                            }
                        }
                    }
                }
            }

        }

      

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved