private RegistryKey[] ScopeToRoots(StartupEntryScope scope) { RegistryKey[] roots = { }; switch (scope) { case StartupEntryScope.All: roots = new[] { Registry.LocalMachine, Registry.CurrentUser }; break; case StartupEntryScope.Machine: roots = new[] { Registry.LocalMachine }; break; case StartupEntryScope.User: roots = new[] { Registry.CurrentUser }; break; } return(roots); }
private List <string> GetDisallowedItems(StartupLocation location, StartupEntryScope?overrideScope = null) { List <string> disallowedApps = new List <string>(); if (!string.IsNullOrEmpty(location.ApprovedLocation)) { StartupEntryScope scope = overrideScope ?? location.Scope; RegistryKey[] roots = ScopeToRoots(scope); foreach (var root in roots) { try { RegistryKey registryKey = root.OpenSubKey(location.ApprovedLocation, false); if (registryKey != null && registryKey.ValueCount > 0) { foreach (var valueName in registryKey.GetValueNames()) { if (((byte[])registryKey.GetValue(valueName))[0] % 2 != 0) // if value is odd number, item is disabled { disallowedApps.Add(valueName); CairoLogger.Instance.Debug($"StartupRunner: Skipping disabled entry: {valueName}"); } } } // close key when finished registryKey?.Close(); } catch { CairoLogger.Instance.Warning($"StartupRunner: Unable to load allowed startup items list from registry key {location.ApprovedLocation}"); } } } return(disallowedApps); }