應一個網友的需求,寫了下面的,獲取本機安裝的軟件的清單,希望對有需要的人,有幫助吧
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 中顯示,每行一個。