
/// <summary> /// 獲取所有已經安裝的程序 /// </summary> /// <param name="reg"></param> /// <returns>程序名稱,安裝路徑</returns> private static List<Dictionary<string, string>> GetProgramAndPath() { var reg = new string[] { @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" }; string tempType = null; int softNum = 0;//所有已經安裝的程序數量 RegistryKey currentKey = null; var ls = new List<Dictionary<string, string>>(); foreach (var item222 in reg) { object displayName = null, uninstallString = null, installLocation = null, releaseType = null; RegistryKey pregkey = Registry.LocalMachine.OpenSubKey(item222);//獲取指定路徑下的鍵 foreach (string item in pregkey.GetSubKeyNames()) //循環所有子鍵 { currentKey = pregkey.OpenSubKey(item); displayName = currentKey.GetValue("DisplayName"); //獲取顯示名稱 installLocation = currentKey.GetValue("InstallLocation"); //獲取安裝路徑 uninstallString = currentKey.GetValue("UninstallString"); //獲取卸載字符串路徑 releaseType = currentKey.GetValue("ReleaseType"); //發行類型,值是Security Update為安全更新,Update為更新 bool isSecurityUpdate = false; if (releaseType != null) { tempType = releaseType.ToString(); if (tempType == "Security Update" || tempType == "Update") { isSecurityUpdate = true; } } if (!isSecurityUpdate && displayName != null && uninstallString != null) { softNum++; if (installLocation == null) { ls.Add(new Dictionary<string, string> { { displayName.ToString(), "" } }); } else { ls.Add(new Dictionary<string, string> { { displayName.ToString(), installLocation.ToString() } }); } } } } return ls; }