zoukankan      html  css  js  c++  java
  • 测试篇 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
  • 相关阅读:
    3.redis认证
    2.redis-help使用,基本命令
    安卓使用merge标签和include优化UI布局
    安卓数据存储之ContentProvider
    安卓数据存储之SQLLite
    安卓数据存储之SharePreference
    安卓数据存储之sdcard存储
    java解析json之gjson和fastjson
    Android Volley完全解析(一),初识Volley的基本用法
    使用Pull解析Xml文件
  • 原文地址:https://www.cnblogs.com/JJBox/p/10439408.html
Copyright © 2011-2022 走看看