• 测试篇 c#遍历所有安装程序 获取所有已经安装的程序


      /// <summary>
            /// 获取所有已经安装的程序
            /// </summary>
            /// <param name="reg"></param>
            /// <returns>程序名称,安装路径</returns> 
            private static List<Dictionary<string, string>> GetProgramAndPath()
            {
                var reg = new string[] {
                    @"SOFTWAREMicrosoftWindowsCurrentVersionUninstall",
                    @"SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall"
                };
                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;
            }
    View Code
  • 相关阅读:
    注册表解锁
    Windows错误代码大全 2
    硬盘数据线的问题
    vs2010与C#4.0新特性
    (转载)C语言负数的移位运算
    (转载)看C语言编码转换负数的二进制表示方法
    (转载)C语言右移运算符的问题(特别当与取反运算符一起时)
    (转载)Qt中使用cout输出的方法
    (转载)QPainter的用法
    (转载)Qt计算MD5
  • 原文地址:https://www.cnblogs.com/JJBox/p/10439408.html
Copyright © 2020-2023  润新知