c# 遍历所有安装程序 获取所有已经安装的程序

        /// <summary>
        /// 获取所有已经安装的程序
        /// </summary>
        /// <param name="reg"></param>
        /// <returns></returns> 
        private static string GetChengxu()
        {
            var reg = new string[] {
                @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
                @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
            };
            string temp = null, tempType = null;
            foreach (var item222 in reg)
            {
                object displayName = null, uninstallString = null, releaseType = null;
                RegistryKey currentKey = null;
                int softNum = 0;
                RegistryKey pregkey = Registry.LocalMachine.OpenSubKey(item222);//获取指定路径下的键 
                foreach (string item in pregkey.GetSubKeyNames())               //循环所有子键
                {
                    currentKey = pregkey.OpenSubKey(item);
                    displayName = currentKey.GetValue("DisplayName");           //获取显示名称
                    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++;
                        temp += displayName.ToString() + Environment.NewLine;
                    }
                }
                // var str = "您本机安装了" + softNum.ToString() + "个" + Environment.NewLine + temp;
            }
            return temp;
        }
View Code

猜你喜欢

转载自www.cnblogs.com/JJBox/p/10439408.html