1. /// <summary>
    2. /// 获取所有已经安装的程序
    3. /// </summary>
    4. /// <param name="reg"></param>
    5. /// <returns>程序名称,安装路径</returns>
    6. private static List<Dictionary<string, string>> GetProgramAndPath()
    7. {
    8. var reg = new string[] {
    9. @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
    10. @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
    11. };
    12. string tempType = null;
    13. int softNum = 0;//所有已经安装的程序数量
    14. RegistryKey currentKey = null;
    15. var ls = new List<Dictionary<string, string>>();
    16. foreach (var item222 in reg)
    17. {
    18. object displayName = null, uninstallString = null, installLocation = null, releaseType = null;
    19. RegistryKey pregkey = Registry.LocalMachine.OpenSubKey(item222);//获取指定路径下的键
    20. foreach (string item in pregkey.GetSubKeyNames()) //循环所有子键
    21. {
    22. currentKey = pregkey.OpenSubKey(item);
    23. displayName = currentKey.GetValue("DisplayName"); //获取显示名称
    24. installLocation = currentKey.GetValue("InstallLocation"); //获取安装路径
    25. uninstallString = currentKey.GetValue("UninstallString"); //获取卸载字符串路径
    26. releaseType = currentKey.GetValue("ReleaseType"); //发行类型,值是Security Update为安全更新,Update为更新
    27. bool isSecurityUpdate = false;
    28. if (releaseType != null)
    29. {
    30. tempType = releaseType.ToString();
    31. if (tempType == "Security Update" || tempType == "Update")
    32. {
    33. isSecurityUpdate = true;
    34. }
    35. }
    36. if (!isSecurityUpdate && displayName != null && uninstallString != null)
    37. {
    38. softNum++;
    39. if (installLocation == null)
    40. {
    41. ls.Add(new Dictionary<string, string> { { displayName.ToString(), "" } });
    42. }
    43. else
    44. {
    45. ls.Add(new Dictionary<string, string> { { displayName.ToString(), installLocation.ToString() } });
    46. }
    47. }
    48. }
    49. }
    50. return ls;
    51. }