public int Install() { int result = 0; Console.WriteLine("Start Install.."); this.withThrowExceptionIfPermissionDeneed(); if (isTargetTask()) { throw new InvalidOperationException("Task has already been setup. Please uninstall first."); } // TODO: Registry save (Only on first run) // create shortcut //string path = AppDomain.CurrentDomain.BaseDirectory; string exeFullPathFileName = Process.GetCurrentProcess().MainModule.FileName; //Console.WriteLine($"path : {path}"); //Console.WriteLine($"name : {exeFullPathFileName}"); // create shortcut ShortcutCreator shortcut = new ShortcutCreator(exeFullPathFileName, "-s", ShortcutCreator.TargetSpecialFolder.CommonPrograms); shortcut.AppUserModelID = Program.generateDefaultAppUserModelID(); shortcut.create(); // create task using (TaskService taskService = new TaskService()) { // regist task scheduler TimeSpan span = TimeSpan.FromHours(1); Task task = taskService.Execute(exeFullPathFileName).WithArguments("-s").AtLogon().RepeatingEvery(span).AsTask(D_PREVENT_REBOOT_TASK); TaskDefinition definition = task.Definition; TaskPrincipal principal = definition.Principal; principal.RunLevel = TaskRunLevel.Highest; principal.UserId = "SYSTEM"; TaskRegistrationInfo info = definition.RegistrationInfo; info.Author = "PreventReboot"; info.Description = "This program prevents reboot during login by updating the ActiveTime of Windows10 on a regular basis."; TaskSettings settings = definition.Settings; settings.DisallowStartIfOnBatteries = false; settings.StopIfGoingOnBatteries = false; settings.RunOnlyIfIdle = false; settings.Hidden = true; settings.Enabled = true; settings.StartWhenAvailable = true; IdleSettings idle = settings.IdleSettings; idle.RestartOnIdle = false; idle.StopOnIdleEnd = false; task.RegisterChanges(); } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="Settings"/> class. /// </summary> public InstanceSettings(GlobalSettings globalSettings) { Global = globalSettings; Away = new AwaySettings(); BadNickname = new BadNicknameSettings(); Control = new ControlSettings(); Event = new EventSettings(); Idle = new IdleSettings(); Message = new MessageSettings(); Record = new RecordSettings(); Sticky = new StickySettings(); TeamSpeak = new TeamSpeakServerSettings(); Vote = new VoteSettings(); }
/// <summary> /// Initializes a new instance of the <see cref="Settings"/> class. /// </summary> public InstanceSettings(GlobalSettings globalSettings) { Global = globalSettings; Away = new AwaySettings(); BadNickname = new BadNicknameSettings(); Control = new ControlSettings(); Event = new EventSettings(); Idle = new IdleSettings(); Message = new MessageSettings(); Record = new RecordSettings(); Sticky = new StickySettings(); TeamSpeak = new TeamSpeakServerSettings(); Vote = new VoteSettings(); }
/// <summary> /// Determines whether the specified client is idle. /// </summary> /// <param name="client">The client.</param> /// <param name="settings">The settings.</param> /// <returns> /// <c>true</c> if the specified client is idle; otherwise, <c>false</c>. /// </returns> public static bool IsIdle(this ClientListEntry client, IdleSettings settings) { return settings.Enabled && settings.Channel > 0 && client.ClientIdleDuration.GetValueOrDefault().TotalMinutes >= settings.IdleTime; }
/// <summary> /// Determines whether the specified client is idle. /// </summary> /// <param name="client">The client.</param> /// <param name="settings">The settings.</param> /// <returns> /// <c>true</c> if the specified client is idle; otherwise, <c>false</c>. /// </returns> public static bool IsIdle(this ClientListEntry client, IdleSettings settings) { return(settings.Enabled && settings.Channel > 0 && client.ClientIdleDuration.GetValueOrDefault().TotalMinutes >= settings.IdleTime); }