# 新建任务

命令行：

```
# On System Startschtasks /create /tn qwqdanchun /tr "c:\Temp\qwqdanchun.exe" /sc onstart /ru System# On User Idle (30mins)schtasks /create /tn qwqdanchun /tr "c:\Temp\qwqdanchun.exe" /sc onidle /i 30# On User Loginschtasks /create /tn qwqdanchun /tr "c:\Temp\qwqdanchun.exe" /sc onlogon /ru System
```

Powershell：

```
$A = New-ScheduledTaskAction -Execute "cmd.exe" -Argument "/c c:\Temp\qwqdanchun.exe"$T = New-ScheduledTaskTrigger -AtLogOn -User "qwqdanchun"$P = New-ScheduledTaskPrincipal "NT AUTHORITY\SYSTEM" -RunLevel Highest$S = New-ScheduledTaskSettingsSet$P = New-ScheduledTaskPrincipal "qwqdanchun"$D = New-ScheduledTask -Action $A -Trigger $T -Principal $P -Settings $SRegister-ScheduledTask qwqdanchun -InputObjec $D
```

C#：

```
using Microsoft.Win32.TaskScheduler;using System;namespace demo{    static class Program    {        static void Main()        {            TaskService ts = new TaskService();            TaskDefinition td = ts.NewTask();            td.RegistrationInfo.Description = "This task keeps your Adobe Reader and Acrobat applications up to date with the latest enhancements and security fixes";            td.RegistrationInfo.Author = "Adobe Scheduler";            TimeTrigger dt = new TimeTrigger();            dt.StartBoundary = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 06:30:00"));            dt.Repetition.Interval = TimeSpan.FromMinutes(5);            td.Triggers.Add(dt);            td.Settings.DisallowStartIfOnBatteries = false;            td.Settings.RunOnlyIfNetworkAvailable = true;            td.Settings.RunOnlyIfIdle = false;            td.Settings.DisallowStartIfOnBatteries = false;            td.Actions.Add(new ExecAction(@"c:\Temp\qwqdanchun.exe", "", null));            ts.RootFolder.RegisterTaskDefinition(@"Adobe Acrobat Update Task", td);        }    }}
```

参考文章：

{% embed url="<https://docs.microsoft.com/zh-cn/windows/win32/taskschd/using-the-task-scheduler>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.qwqdanchun.com/persistence/schtasks/add-schtasks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
