dahall / TaskScheduler

Provides a .NET wrapper for the Windows Task Scheduler. It aggregates the multiple versions, provides an editor and allows for localization.
MIT License
1.2k stars 191 forks source link

How to start my task in admin #923

Closed dickxuwen closed 2 years ago

dickxuwen commented 2 years ago

How to start a scheduled task with the highest permission?

How do I make a scheduled task run without AC power?

dahall commented 2 years ago
// Create definition
TaskDefinition td = TaskService.Instance.NewTask();

// Set the run level to the highest privilege
td.Principal.RunLevel = TaskRunLevel.Highest;

// These settings will ensure it runs even if on battery power
td.Settings.DisallowStartIfOnBatteries = false;
td.Settings.StopIfGoingOnBatteries = false;
dickxuwen commented 2 years ago

It works. Thank you very much!

@.***

From: David Hall Date: 2021-11-29 11:13 To: dahall/TaskScheduler CC: dickxuwen; Author Subject: Re: [dahall/TaskScheduler] How to start my task in admin (Issue #923) // Create definition TaskDefinition td = TaskService.Instance.NewTask(); // Set the run level to the highest privilege td.Principal.RunLevel = TaskRunLevel.Highest; // These settings will ensure it runs even if on battery power td.Settings.DisallowStartIfOnBatteries = false; td.Settings.StopIfGoingOnBatteries = false; — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.