public StateChange ToggleStartupState(StartupList program, bool enable) { try { using (var taskService = new TaskService()) { Func <Task, bool> namePredicate = x => x.Name.Equals(program.Name, StringComparison.OrdinalIgnoreCase) && x.Definition.Triggers.Any(x => x.TriggerType == TaskTriggerType.Logon); var task = GetTaskFromFolder(TaskService.Instance.RootFolder, namePredicate, GetFolderPredicate(false)) !; var isAlreadyTheRequestState = task.Enabled == enable; if (isAlreadyTheRequestState) { return(StateChange.SameState); } else { task.Enabled = enable; return(StateChange.Success); } } } catch (UnauthorizedAccessException) { return(StateChange.Unauthorized); } }
public StateChange ToggleStartupState(StartupList program, bool enable) { try { using (var reg = GetWriteRegistryKey(program.DisabledRegistryPath, program.AllUsers)) { byte[] bytes; if (enable) { bytes = EnabledBytes; } else { bytes = MakeDisabledBytes(); } var currentValue = (byte[])reg.GetValue(program.RegistryName); if (currentValue == null) { reg.SetValue(program.RegistryName, bytes); return(StateChange.Success); } var isAlreadyTheRequestState = new ReadOnlySpan <byte>(bytes.Take(4).ToArray()).SequenceEqual(currentValue.Take(4).ToArray()); if (isAlreadyTheRequestState) { return(StateChange.SameState); } else { reg.SetValue(program.RegistryName, bytes); return(StateChange.Success); } } } catch (UnauthorizedAccessException) { return(StateChange.Unauthorized); } }
public void RemoveProgramFromStartup(StartupList program) { File.Delete(program.Path); }
public void RemoveProgramFromStartup(StartupList program) { using (var key = GetWriteRegistryKey(program.RegistryPath, program.AllUsers)) { key.DeleteValue(program.RegistryName); } }
private static void DeleteRegistryKey(StartupList program) { using (var key = GetWriteRegistryKey(program.RegistryPath, program.AllUsers)) { key.DeleteValue(program.RegistryName); } }