Exemple #1
0
        /// <summary>
        /// Returns all values in that registy path with the given name
        /// </summary>
        /// <param name="registryPath"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static List <RegistryEntry> GetPrograms()
        {
            var curr = DateTime.Now;
            var div  = curr - _lastRefreshed;

            if (_values == null || div.TotalSeconds > 1)
            {
                Log.Debug("Getting programs from registry...");
                Stopwatch w = new Stopwatch();
                w.Start();
                _values = new List <RegistryEntry>();
                var           currentList = new List <RegistryEntry>();
                RegistryEntry entry       = new RegistryEntry();
                foreach (var paths in _registryProgramPaths)
                {
                    foreach (RegistryView v in _views)
                    {
                        using (RegistryKey rk = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, v).OpenSubKey(paths))
                        {
                            foreach (string skName in rk.GetSubKeyNames())
                            {
                                using (RegistryKey sk = rk.OpenSubKey(skName))
                                {
                                    Log.Verbose("Processing program registry entry", sk);
                                    try
                                    {
                                        entry                  = new RegistryEntry();
                                        entry.DisplayName      = sk.GetValue("DisplayName")?.ToString() ?? "";
                                        entry.DisplayVersion   = sk.GetValue("DisplayVersion")?.ToString() ?? "";
                                        entry.PreRelease       = entry.DisplayName.Contains("rc") || entry.DisplayName.Contains("beta");
                                        entry.InstallationPath = sk.GetValue("InstallLocation")?.ToString() ?? "";
                                        entry.UninstallString  = sk.GetValue("UninstallString")?.ToString() ?? "";
                                        entry.Publisher        = sk.GetValue("Publisher")?.ToString() ?? "";
                                        entry.InstallationDate = sk.GetValue("InstallDate")?.ToString() ?? "";
                                        entry.ModifyPath       = sk.GetValue("ModifyPath")?.ToString() ?? "";
                                        entry.WindowsInstaller = Convert.ToBoolean(sk.GetValue("WindowsInstaller") ?? false);

                                        if (!currentList.Exists(x => x.DisplayName.Contains(entry.DisplayName)))
                                        {
                                            currentList.Add(entry);
                                        }
                                    }
                                    catch (NullReferenceException ex)
                                    {
                                        Log.Error(ex, $"Error formatting Registry values to RegistryEntry", entry.DisplayName);
                                    }
                                }
                            }
                        }
                    }
                }
                w.Stop();
                Log.Debug($"Finished getting programs from registry in {w.ElapsedMilliseconds} ms");
                _values = currentList;
            }
            _lastRefreshed = DateTime.Now;
            return(_values);
        }
Exemple #2
0
 private static void ConvertFromRegistryEntry(out IProgramEntry entry, RegistryEntry regEntry, ProgramType type)
 {
     entry = new VKProgramEntry(regEntry.DisplayName, new Models.Version(regEntry.DisplayVersion, regEntry.PreRelease));
     entry.ComponentType    = type;
     entry.InstallationDate = regEntry.InstallationDate;
     entry.InstallationPath = regEntry.InstallationPath;
     entry.ModifyPath       = regEntry.ModifyPath;
     entry.Publisher        = regEntry.Publisher;
     entry.UninstallString  = regEntry.UninstallString;
     entry.WindowsInstaller = regEntry.WindowsInstaller;
     if (entry.ComponentType == ProgramType.MediaEncoder)
     {
         entry.Hide = true;
     }
 }