Windows 10 - 计划任务 - 关机

Windows 10 - 计划任务 - 关机

我正在尝试让我的 Win10 VM 每天午夜关闭。我已通过 powershell 测试该命令

shutdown /f /s /t 1

完美运行。

我还创建了一个任务,我可以看到它被触发了,但机器没有关闭。如果我尝试自己运行该任务,也会发生同样的情况:

- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name="Microsoft-Windows-TaskScheduler" Guid="{DE7B24EA-73C8-4A09-985D-5BDADCFA9017}" /> 
  <EventID>200</EventID> 
  <Version>1</Version> 
  <Level>4</Level> 
  <Task>200</Task> 
  <Opcode>1</Opcode> 
  <Keywords>0x8000000000000000</Keywords> 
  <TimeCreated SystemTime="2018-01-10T08:02:13.412265700Z" /> 
  <EventRecordID>480</EventRecordID> 
  <Correlation ActivityID="{4C02EED4-A58E-4DC8-B626-1CDA89362E4D}" /> 
  <Execution ProcessID="960" ThreadID="3396" /> 
  <Channel>Microsoft-Windows-TaskScheduler/Operational</Channel> 
  <Computer>PC</Computer> 
  <Security UserID="S-1-5-18" /> 
  </System>
- <EventData Name="ActionStart">
  <Data Name="TaskName">\Custom\Shutdown</Data> 
  <Data Name="ActionName">C:\Windows\System32\shutdown.exe</Data> 
  <Data Name="TaskInstanceId">{4C02EED4-A58E-4DC8-B626-1CDA89362E4D}</Data> 
  <Data Name="EnginePID">4624</Data> 
  </EventData>
  </Event>

- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name="Microsoft-Windows-TaskScheduler" Guid="{DE7B24EA-73C8-4A09-985D-5BDADCFA9017}" /> 
  <EventID>201</EventID> 
  <Version>2</Version> 
  <Level>4</Level> 
  <Task>201</Task> 
  <Opcode>2</Opcode> 
  <Keywords>0x8000000000000000</Keywords> 
  <TimeCreated SystemTime="2018-01-10T08:02:13.720117600Z" /> 
  <EventRecordID>482</EventRecordID> 
  <Correlation ActivityID="{4C02EED4-A58E-4DC8-B626-1CDA89362E4D}" /> 
  <Execution ProcessID="960" ThreadID="3396" /> 
  <Channel>Microsoft-Windows-TaskScheduler/Operational</Channel> 
  <Computer>PC</Computer> 
  <Security UserID="S-1-5-18" /> 
  </System>
- <EventData Name="ActionSuccess">
  <Data Name="TaskName">\Custom\Shutdown</Data> 
  <Data Name="TaskInstanceId">{4C02EED4-A58E-4DC8-B626-1CDA89362E4D}</Data> 
  <Data Name="ActionName">C:\Windows\System32\shutdown.exe</Data> 
  <Data Name="ResultCode">2147942401</Data> 
  <Data Name="EnginePID">4624</Data> 
  </EventData>
  </Event>

有人能指出我这里的问题吗?以下是导出的任务:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2018-01-09T23:18:33.1522429</Date>
    <Author>PC\user</Author>
    <URI>\Custom\Shutdown</URI>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2018-01-10T00:55:00</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>xxxxxxx</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
    <AllowHardTerminate>false</AllowHardTerminate>
    <StartWhenAvailable>true</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <Duration>PT10M</Duration>
      <WaitTimeout>PT1H</WaitTimeout>
      <StopOnIdleEnd>false</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>true</RunOnlyIfIdle>
    <WakeToRun>true</WakeToRun>
    <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
    <Priority>7</Priority>
    <RestartOnFailure>
      <Interval>PT1H</Interval>
      <Count>3</Count>
    </RestartOnFailure>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Windows\System32\shutdown.exe</Command>
      <Arguments>\f \s \t 1</Arguments>
    </Exec>
  </Actions>

多谢

答案1

看起来您在参数字段中使用了反斜杠 ( \f \s \t 1)

改用这个:

/f /s /t 1

相关内容