Example #1
0
        public static IEnumerable <BrowserHelperEntry> GetBrowserHelpers()
        {
            using (var clsidKey = RegistryTools.OpenRegistryKey(ClsidPath))
            {
                foreach (var registryStartupPoint in RegistryStartupPoints)
                {
                    using (var mainKey = RegistryTools.CreateSubKeyRecursively(registryStartupPoint))
                    {
                        foreach (var browserHelperEntry in
                                 GatherBrowserHelpersFromKey(mainKey, clsidKey, registryStartupPoint, false))
                        {
                            yield return(browserHelperEntry);
                        }

                        using (var disabledKey = mainKey.OpenSubKey(AutorunsDisabledKeyName))
                        {
                            if (disabledKey == null)
                            {
                                continue;
                            }

                            foreach (var browserHelperEntry in
                                     GatherBrowserHelpersFromKey(disabledKey, clsidKey, registryStartupPoint, true))
                            {
                                yield return(browserHelperEntry);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        ///     Look for registry values in the run keys
        /// </summary>
        private static IEnumerable <StartupEntry> GetRegStartupItems(StartupPointData point)
        {
            var results = new List <StartupEntry>();

            try
            {
                using (var rKey = RegistryTools.OpenRegistryKey(point.Path))
                {
                    if (rKey != null)
                    {
                        results.AddRange(from name in rKey.GetValueNames()
                                         let result = rKey.GetValue(name) as string
                                                      where !string.IsNullOrEmpty(result)
                                                      select new StartupEntry(point, name, result));
                    }
                }
            }
            catch (ArgumentException)
            {
                // Key doesn't exist, create it
                RegistryTools.CreateSubKeyRecursively(point.Path)?.Close();
            }

            return(results);
        }
 private static void SetDisabled(StartupEntry startupEntry, bool disabled)
 {
     using (var key = RegistryTools.CreateSubKeyRecursively(GetStartupApprovedKey(startupEntry)))
     {
         key.SetValue(startupEntry.EntryLongName, disabled ? DisabledBytes : EnabledBytes,
                      RegistryValueKind.Binary);
     }
 }
 private static bool GetDisabled(StartupEntry startupEntry)
 {
     using (var key = RegistryTools.CreateSubKeyRecursively(GetStartupApprovedKey(startupEntry)))
     {
         var bytes = key.GetValue(startupEntry.EntryLongName) as byte[];
         return(bytes != null && bytes.Length > 0 && !bytes[0].Equals(0x02));
     }
 }
        /// <summary>
        ///     Create a registry value for the specified entry. Works for drive links as well.
        /// </summary>
        /// <param name="startupEntry"></param>
        internal static void CreateRegValue(StartupEntry startupEntry)
        {
            if (string.IsNullOrEmpty(startupEntry.Command))
            {
                return;
            }

            using (var runKey = RegistryTools.CreateSubKeyRecursively(startupEntry.ParentLongName))
            {
                runKey.SetValue(startupEntry.EntryLongName, startupEntry.Command, RegistryValueKind.String);
            }
        }
Example #6
0
 private static bool GetDisabled(StartupEntry startupEntry)
 {
     try
     {
         using (var key = RegistryTools.CreateSubKeyRecursively(GetStartupApprovedKey(startupEntry)))
         {
             var bytes = key.GetValue(startupEntry.EntryLongName) as byte[];
             return(bytes != null && bytes.Length > 0 && !bytes[0].Equals(0x02));
         }
     }
     catch (SystemException ex)
     {
         Console.WriteLine(ex);
         return(false);
     }
 }
Example #7
0
        public static IEnumerable <BrowserHelperEntry> GetBrowserHelpers()
        {
            using (var clsidKey = RegistryTools.OpenRegistryKey(ClsidPath))
            {
                foreach (var registryStartupPoint in RegistryStartupPoints)
                {
                    RegistryKey mainKey;

                    try
                    {
                        mainKey = RegistryTools.CreateSubKeyRecursively(registryStartupPoint);
                    }
                    catch (UnauthorizedAccessException e)
                    {
                        Console.WriteLine(e);
                        continue;
                    }

                    using (mainKey)
                    {
                        foreach (var browserHelperEntry in
                                 GatherBrowserHelpersFromKey(mainKey, clsidKey, registryStartupPoint, false))
                        {
                            yield return(browserHelperEntry);
                        }

                        using (var disabledKey = mainKey.OpenSubKey(AutorunsDisabledKeyName))
                        {
                            if (disabledKey == null)
                            {
                                continue;
                            }

                            foreach (var browserHelperEntry in
                                     GatherBrowserHelpersFromKey(disabledKey, clsidKey, registryStartupPoint, true))
                            {
                                yield return(browserHelperEntry);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        ///     Look for registry values in the run keys
        /// </summary>
        private static IEnumerable <StartupEntry> GetRegStartupItems(StartupPointData point)
        {
            var results = new List <StartupEntry>();

            try
            {
                using (var rKey = RegistryTools.OpenRegistryKey(point.Path))
                {
                    if (rKey != null)
                    {
                        foreach (var name in rKey.GetValueNames())
                        {
                            var result = rKey.GetStringSafe(name);
                            if (string.IsNullOrEmpty(result))
                            {
                                continue;
                            }

                            try
                            {
                                results.Add(new StartupEntry(point, name, result));
                            }
                            catch (Exception ex)
                            {
                                PremadeDialogs.GenericError(ex);
                            }
                        }
                    }
                }
            }
            catch (ArgumentException)
            {
                // Key doesn't exist, create it
                RegistryTools.CreateSubKeyRecursively(point.Path)?.Close();
            }
            catch (SecurityException ex)
            {
                Console.WriteLine(@"Failed to process startup entries: " + ex);
            }

            return(results);
        }
Example #9
0
 private void checkBoxBoot_CheckedChanged(object sender, EventArgs e)
 {
     try
     {
         using (var key = RegistryTools.CreateSubKeyRecursively(RunKeyPath))
         {
             if (checkBoxBoot.Checked)
             {
                 key.SetValue(RunKeyValueName, $"\"{Assembly.GetExecutingAssembly().Location}\"");
             }
             else
             {
                 key.DeleteValue(RunKeyValueName);
             }
         }
     }
     catch (Exception ex)
     {
         ShowBootException(ex);
         checkBoxBoot.Enabled = false;
     }
 }
Example #10
0
        /// <summary>
        ///     Look for entries in the disabled startup backup store.
        /// </summary>
        public IEnumerable <StartupEntry> AddDisableInfo(IList <StartupEntry> existingEntries)
        {
            foreach (var entry in existingEntries)
            {
                yield return(entry);
            }

            using (var regDisKey = RegistryTools.CreateSubKeyRecursively(RegistryDisabledKey.Path))
            {
                var badLocations = new List <string>();
                foreach (var subKeyName in regDisKey.GetSubKeyNames())
                {
                    using (var subKey = regDisKey.OpenSubKey(subKeyName))
                    {
                        if (subKey == null)
                        {
                            continue;
                        }

                        var key     = subKey.GetValue("key") as string;
                        var hkey    = subKey.GetValue("hkey") as string;
                        var item    = subKey.GetValue("item") as string;
                        var command = subKey.GetValue("command") as string;
                        if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(hkey) ||
                            string.IsNullOrEmpty(item) || string.IsNullOrEmpty(command))
                        {
                            continue;
                        }

                        var location = Path.Combine(RegistryTools.GetKeyRoot(hkey, false), key);

                        if (string.IsNullOrEmpty(location.Trim()))
                        {
                            continue;
                        }

                        var runLocation = StartupEntryFactory.RunLocations
                                          .FirstOrDefault(x => PathTools.PathsEqual(location, x.Path));

                        if (runLocation != null)
                        {
                            StartupEntry startupEntry;
                            try
                            {
                                startupEntry = new StartupEntry(runLocation, item, command)
                                {
                                    DisabledStore = true
                                };
                            }
                            catch
                            {
                                badLocations.Add(location);
                                continue;
                            }
                            yield return(startupEntry);
                        }
                        else
                        {
                            badLocations.Add(location);
                        }
                    }
                }

#if DEBUG
                if (badLocations.Any())
                {
                    throw new InvalidDataException(Localisation.Error_InvalidRegKeys + "\n"
                                                   +
                                                   string.Join("\n", badLocations.Distinct().OrderBy(x => x).ToArray()));
                }
#endif
            }

            using (var hddDisKey = RegistryTools.CreateSubKeyRecursively(DriveDisabledKey.Path))
            {
                foreach (var subKeyName in hddDisKey.GetSubKeyNames())
                {
                    using (var subKey = hddDisKey.OpenSubKey(subKeyName))
                    {
                        if (subKey == null)
                        {
                            continue;
                        }

                        var path     = subKey.GetValue("path") as string;
                        var location = subKey.GetValue("location") as string;
                        var backup   = subKey.GetValue("backup") as string;
                        var command  = subKey.GetValue("command") as string;
                        if (backup == null || location == null || path == null || command == null)
                        {
                            continue;
                        }

                        var runLocation =
                            StartupEntryFactory.RunLocations.FirstOrDefault(x => PathTools.PathsEqual(x.Path, location));

                        yield return(new StartupEntry(runLocation, Path.GetFileName(path), command)
                        {
                            BackupPath = backup,
                            DisabledStore = true
                        });
                    }
                }
            }
        }
Example #11
0
        /// <summary>
        ///     Create a new record in the appropriate disabled entry store. If the entry already exists it is overwritten.
        /// </summary>
        /// <param name="startupEntry">Startup entry to create the record for</param>
        /// <param name="newEntryPath">Full path to the new backup file</param>
        private static void CreateDisabledEntry(StartupEntry startupEntry, string newEntryPath)
        {
            using (var disabledStartupEntryStore = RegistryTools.CreateSubKeyRecursively(
                       startupEntry.IsRegKey ? RegistryDisabledKey.Path : DriveDisabledKey.Path))
            {
                var disabledSubKeyName = startupEntry.IsRegKey
                    ? startupEntry.EntryLongName
                    : startupEntry.FullLongName.Replace('\\', '^');
                var disabledSubkeyKey =
                    disabledStartupEntryStore.GetSubKeyNames()
                    .FirstOrDefault(x => disabledSubKeyName.Equals(x, StringComparison.InvariantCultureIgnoreCase));

                // Clean up old disabled entry if any
                if (!string.IsNullOrEmpty(disabledSubkeyKey))
                {
                    disabledStartupEntryStore.DeleteSubKey(disabledSubkeyKey);
                }

                using (
                    var storeSubkey = disabledStartupEntryStore.CreateSubKey(disabledSubKeyName,
                                                                             RegistryKeyPermissionCheck.ReadWriteSubTree))
                {
                    if (storeSubkey == null)
                    {
                        return;
                    }

                    if (startupEntry.IsRegKey)
                    {
                        storeSubkey.SetValue("key", RegistryTools.StripKeyRoot(startupEntry.ParentLongName),
                                             RegistryValueKind.String);
                        storeSubkey.SetValue("item", startupEntry.EntryLongName, RegistryValueKind.String);
                        storeSubkey.SetValue("hkey", RegistryTools.GetKeyRoot(startupEntry.ParentLongName, true),
                                             RegistryValueKind.String);
                        storeSubkey.SetValue("inimapping", 0, RegistryValueKind.String);
                    }
                    else
                    {
                        storeSubkey.SetValue("item",
                                             Path.GetFileNameWithoutExtension(startupEntry.EntryLongName) ?? string.Empty,
                                             RegistryValueKind.String);
                        storeSubkey.SetValue("path", startupEntry.FullLongName, RegistryValueKind.String);
                        storeSubkey.SetValue("location", startupEntry.ParentLongName, RegistryValueKind.String);
                        storeSubkey.SetValue("backup", newEntryPath, RegistryValueKind.String);
                        storeSubkey.SetValue("backupExtension", BackupExtension, RegistryValueKind.String);
                    }

                    // Command stays the same for both
                    storeSubkey.SetValue("command", startupEntry.Command, RegistryValueKind.String);

                    // Set the disable date
                    var now = DateTime.Now;
                    storeSubkey.SetValue("YEAR", now.Year, RegistryValueKind.DWord);
                    storeSubkey.SetValue("MONTH", now.Month, RegistryValueKind.DWord);
                    storeSubkey.SetValue("DAY", now.Day, RegistryValueKind.DWord);
                    storeSubkey.SetValue("HOUR", now.Hour, RegistryValueKind.DWord);
                    storeSubkey.SetValue("MINUTE", now.Minute, RegistryValueKind.DWord);
                    storeSubkey.SetValue("SECOND", now.Second, RegistryValueKind.DWord);
                }
            }
        }