电池电量不足时 Windows 任务计划程序不会启动任务

电池电量不足时 Windows 任务计划程序不会启动任务

我创建了任务,SCHTASKS.EXE /create /tn "TaskName" /ru system /xml ".\TaskName.xml" 这是内容TaskName.xml

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2023-01-09T16:19:18</Date>
    <Author>AuthorName</Author>
    <URI>\AppName</URI>
  </RegistrationInfo>
  <Triggers>
    <LogonTrigger>
      <StartBoundary>2023-01-09T16:19:00</StartBoundary>
      <Enabled>true</Enabled>
    </LogonTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>S-1-5-18</UserId>
      <RunLevel>LeastPrivilege</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>false</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
    <Priority>7</Priority>
    <RestartOnFailure>
      <Interval>PT1M</Interval>
      <Count>3</Count>
    </RestartOnFailure>
  </Settings>
    <Actions Context="Author">
        <Exec>
            <Command>"C:\Program Files (x86)\Myapp\Myapp.exe"</Command>
        </Exec>
    </Actions>
</Task>

正如您所见DisallowStartIfOnBatterie,并且StopIfGoingOnBatterie都设置为false

但直到插入笔记本电脑的交流电源后,任务才会以低功耗启动。

https://learn.microsoft.com/en-us/windows-hardware/design/component-guidelines/battery-saver提到:

Windows task scheduler tasks trigger only if the task is:

Not set to Start the task only if the computer is idle... (task doesn't use IdleSettings)

Not set to run during automatic maintenance (task doesn't use MaintenanceSettings)

Is set to Run only when user is logged on (task LogonType is TASK_LOGON_INTERACTIVE_TOKEN or TASK_LOGON_GROUP)

我应该如何在 .xml 文件中设置登录类型?

相关内容