利用注册表获取本机安装的软件

来源:互联网 发布:巴西统计年鉴数据库 编辑:程序博客网 时间:2024/05/31 06:23
    private List<string> GetInstalledPrograms()//返回一个List<string>包括了电脑上安装的软件列表        {            List<string> returnProgramsList = new List<string>();            object displayName = null;            object uninstallString = null;            object releaseType = null;            RegistryKey currentRegistryKey = null;            RegistryKey rootRegistryKey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");//获取指定路径下的键            try            {                foreach (string t in rootRegistryKey.GetSubKeyNames())               //循环所有子键                {                    currentRegistryKey = rootRegistryKey.OpenSubKey(t);                    displayName = currentRegistryKey.GetValue("DisplayName");           //获取显示名称                    uninstallString = currentRegistryKey.GetValue("UninstallString");   //获取卸载字符串路径                    releaseType = currentRegistryKey.GetValue("ReleaseType");           //发行类型,值是Security Update为安全更新,Update为更新                    bool isSecurityUpdate = false;                    if (releaseType != null)                    {                        string tempType = releaseType.ToString();                        if (tempType == "Security Update" || tempType == "Update")                            isSecurityUpdate = true;                    }                    if (!isSecurityUpdate && displayName != null && uninstallString != null)                    {                        returnProgramsList.Add(displayName.ToString());                    }                }            }            catch (Exception ex)            {                MessageBox.Show(ex.Message);            }            return returnProgramsList;        }

0 0
原创粉丝点击