private static RegistryKey GetRegistryKeyFromAutostartLocation(AutostartLocation autostartLocation, bool isEnabled, bool writeable) { return(isEnabled ? GetRegistryKeyFromAutostartLocation(autostartLocation, writeable) : GetDisabledSubKey(autostartLocation, writeable)); }
private static void CreateDisabledFolder(AutostartLocation autostartLocation) { var directory = GetDirectoryFromAutostartLocation(autostartLocation, false); if (!directory.Exists) { directory.Create(); } }
public static void RemoveAutostartEntry(AutostartLocation autostartLocation, string name, bool isEnabled) { if ((int)autostartLocation < 100) { RegistryAutostart.RemoveAutostartEntry(autostartLocation, name, isEnabled); } else { FolderAutostart.RemoveAutostartEntry(autostartLocation, name, isEnabled); } }
private static DirectoryInfo GetDirectoryFromAutostartLocation(AutostartLocation autostartLocation, bool isEnabled) { var directory = GetDirectoryFromAutostartLocation(autostartLocation); if (!isEnabled) { directory = new DirectoryInfo(Path.Combine(directory.FullName, "AutorunsDisabled")); } return(directory); }
public static void RemoveAutostartEntry(AutostartLocation autostartLocation, string name, bool isEnabled) { using (var registryKey = GetRegistryKeyFromAutostartLocation(autostartLocation, isEnabled, true)) registryKey.DeleteValue(name); //Delete the subkey for disabled entries if there aren't any entries left if (!isEnabled) { using (var disabledKey = GetDisabledSubKey(autostartLocation, true)) if (disabledKey != null && disabledKey.ValueCount == 0) { using (var baseKey = GetRegistryKeyFromAutostartLocation(autostartLocation, true)) baseKey.DeleteSubKey("AutorunsDisabled"); } } }
public static void RemoveAutostartEntry(AutostartLocation autostartLocation, string name, bool isEnabled) { var file = new FileInfo(Path.Combine(GetDirectoryFromAutostartLocation(autostartLocation, isEnabled).FullName, name)); file.Delete(); if (!isEnabled) { var directory = GetDirectoryFromAutostartLocation(autostartLocation, false); //get folder for disabled entries if (directory.GetFileSystemInfos().Length == 0) //if empty { directory.Delete(false); //remove } } }
private static DirectoryInfo GetDirectoryFromAutostartLocation(AutostartLocation autostartLocation) { switch (autostartLocation) { case AutostartLocation.ProgramData: return (new DirectoryInfo(Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"..\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp"))); case AutostartLocation.AppData: return(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Startup))); default: throw new ArgumentOutOfRangeException(nameof(autostartLocation), autostartLocation, null); } }
public static List <AutostartProgramInfo> GetAutostartProgramsFromFolder(AutostartLocation autostartLocation, bool isEnabled) { var result = new List <AutostartProgramInfo>(); try { var directory = GetDirectoryFromAutostartLocation(autostartLocation, isEnabled); if (directory.Exists) { foreach (var fileInfo in directory.GetFiles()) { if (fileInfo.Name == "desktop.ini") { continue; } FileInfo file; if (fileInfo.Extension == ".lnk") { file = new FileInfo(GetShortcutTarget(fileInfo.FullName)); } else { file = fileInfo; } var entry = new AutostartProgramInfo { Name = fileInfo.Name, //This should be fileinfo CommandLine = file.FullName, IsEnabled = isEnabled, AutostartLocation = autostartLocation }; result.Add(AutostartManager.CompleteAutostartProgramInfo(entry)); } } } catch (Exception) { // ignored } return(result); }
public static void ChangeAutostartEntry(AutostartLocation autostartLocation, string name, bool isEnabled) { if (!isEnabled) { CreateDisabledSubKey(autostartLocation); } using (var registryKey = GetRegistryKeyFromAutostartLocation(autostartLocation, !isEnabled, true)) using (var registryKey2 = GetRegistryKeyFromAutostartLocation(autostartLocation, isEnabled, true)) { var value = registryKey.GetValue(name); registryKey2.SetValue(name, value, RegistryValueKind.String); registryKey.DeleteValue(name); //Delete empty disabled key if (isEnabled && registryKey.ValueCount == 0) { registryKey2.DeleteSubKey("AutorunsDisabled"); } } }
public static List <AutostartProgramInfo> GetAutostartProgramsFromRegistryKey( AutostartLocation autostartLocation, bool isEnabled) { var result = new List <AutostartProgramInfo>(); try { using (var registryKey = GetRegistryKeyFromAutostartLocation(autostartLocation, isEnabled, false)) { if (registryKey != null) { foreach (var valueName in registryKey.GetValueNames()) { var value = registryKey.GetValue(valueName) as string; if (value == null) { continue; } var entry = new AutostartProgramInfo { Name = valueName, CommandLine = value, IsEnabled = isEnabled, AutostartLocation = autostartLocation }; result.Add(AutostartManager.CompleteAutostartProgramInfo(entry)); } } } } catch (Exception) { // ignored } return(result); }
private static RegistryKey GetRegistryKeyFromAutostartLocation(AutostartLocation autostartLocation, bool writeable) { switch (autostartLocation) { case AutostartLocation.HKCU_Run: return (Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", writeable)); case AutostartLocation.HKLM_Run: return (Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", writeable)); case AutostartLocation.HKLM_WOWNODE_Run: return (Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run", writeable)); default: throw new ArgumentOutOfRangeException(nameof(autostartLocation), autostartLocation, null); } }
public EntryChangedEventArgs(string name, AutostartLocation autostartLocation, bool isEnabled) { Name = name; AutostartLocation = autostartLocation; IsEnabled = isEnabled; }
private static void CreateDisabledSubKey(AutostartLocation autostartLocation) { using (var baseKey = GetRegistryKeyFromAutostartLocation(autostartLocation, true)) baseKey.CreateSubKey("AutorunsDisabled"); }
private static RegistryKey GetDisabledSubKey(AutostartLocation autostartLocation, bool writeable) { using (var baseKey = GetRegistryKeyFromAutostartLocation(autostartLocation, writeable)) return(baseKey.OpenSubKey("AutorunsDisabled", writeable)); }