예제 #1
0
        private static List <UninstallProgram> GetUninstallProgsFromView(RegistryView view)
        {
            var rootString = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\";

            void SearchRoot(RegistryHive hive, List <UninstallProgram> programs)
            {
                using (var root = RegistryKey.OpenBaseKey(hive, view))
                {
                    var keyList = root.OpenSubKey(rootString);
                    if (keyList == null)
                    {
                        return;
                    }

                    foreach (var key in keyList.GetSubKeyNames())
                    {
                        try
                        {
                            using (var prog = root.OpenSubKey(rootString + key))
                            {
                                if (prog == null)
                                {
                                    continue;
                                }

                                var program = new UninstallProgram()
                                {
                                    DisplayIcon     = prog.GetValue("DisplayIcon")?.ToString(),
                                    DisplayVersion  = prog.GetValue("DisplayVersion")?.ToString(),
                                    DisplayName     = prog.GetValue("DisplayName")?.ToString(),
                                    InstallLocation = prog.GetValue("InstallLocation")?.ToString(),
                                    Publisher       = prog.GetValue("Publisher")?.ToString(),
                                    UninstallString = prog.GetValue("UninstallString")?.ToString(),
                                    URLInfoAbout    = prog.GetValue("URLInfoAbout")?.ToString(),
                                    Path            = prog.GetValue("Path")?.ToString(),
                                    RegistryKeyName = key
                                };

                                programs.Add(program);
                            }
                        }
                        catch (System.Security.SecurityException e)
                        {
                            logger.Warn(e, $"Failed to read registry key {rootString + key}");
                        }
                    }
                }
            }

            var progs = new List <UninstallProgram>();

            SearchRoot(RegistryHive.LocalMachine, progs);
            SearchRoot(RegistryHive.CurrentUser, progs);
            return(progs);
        }
예제 #2
0
파일: Programs.cs 프로젝트: riftgg/Playnite
        private static List <UninstallProgram> GetUninstallProgsFromView(RegistryView view)
        {
            var rootString = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\";

            void SearchRoot(RegistryHive hive, List <UninstallProgram> programs)
            {
                var root    = RegistryKey.OpenBaseKey(hive, view);
                var keyList = root.OpenSubKey(rootString);

                if (keyList == null)
                {
                    return;
                }

                foreach (var key in keyList.GetSubKeyNames())
                {
                    var prog    = root.OpenSubKey(rootString + key);
                    var program = new UninstallProgram()
                    {
                        DisplayIcon     = prog.GetValue("DisplayIcon")?.ToString(),
                        DisplayVersion  = prog.GetValue("DisplayVersion")?.ToString(),
                        DisplayName     = prog.GetValue("DisplayName")?.ToString(),
                        InstallLocation = prog.GetValue("InstallLocation")?.ToString().Replace("\"", string.Empty),
                        Publisher       = prog.GetValue("Publisher")?.ToString(),
                        UninstallString = prog.GetValue("UninstallString")?.ToString(),
                        URLInfoAbout    = prog.GetValue("URLInfoAbout")?.ToString(),
                        Path            = prog.GetValue("Path")?.ToString(),
                        RegistryKeyName = key
                    };

                    programs.Add(program);
                }
            }

            var progs = new List <UninstallProgram>();

            SearchRoot(RegistryHive.LocalMachine, progs);
            SearchRoot(RegistryHive.CurrentUser, progs);
            return(progs);
        }