最好的方法是通过 schtasks 命令行简单地导入 XML。这是一个在 bob 登录时以 bob 身份运行“calc.exe”的示例:
<?xml version="1.0" encoding="UTF-16" ?>
- <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
- <RegistrationInfo>
<Date>2014-10-22T01:50:13</Date>
<Author>user</Author>
</RegistrationInfo>
- <Triggers>
- <LogonTrigger>
<StartBoundary>2014-10-22T01:50:00</StartBoundary>
<Enabled>true</Enabled>
<UserId>WIN7BOX\bob</UserId>
</LogonTrigger>
</Triggers>
- <Principals>
- <Principal id="Author">
<UserId>bob</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
- <Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
- <IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>P3D</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
- <Actions Context="Author">
- <Exec>
<Command>calc.exe</Command>
</Exec>
</Actions>
</Task>