使用具有“跨时区同步"的任务计划程序托管包装器来创建计划任务.选项已禁用 [英] Create scheduled task using Task Scheduler Managed Wrapper with "Synchronize across time zones" option disabled

查看:508
本文介绍了使用具有“跨时区同步"的任务计划程序托管包装器来创建计划任务.选项已禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何使用 Task Scheduler Managed Wrapper Schtasks.exe 未选中跨时区同步" .

Does anybody know how to create a scheduled task using Task Scheduler Managed Wrapper or Schtasks.exe with "Synchronize across time zones" unchecked.

推荐答案

可以使用schtasks.exe进行此操作,但这很棘手.本质上,您必须使用/xml开关并传递具有正确设置了触发器格式的XML文件.

You can do this with schtasks.exe, but it's tricky. Essentially, you have to use the /xml switch and pass an XML file that has the trigger formatted properly.

可以通过在开发机器上的Task Scheduler GUI中完成所需的配置来确定XML文件的基础.然后从上下文菜单中使用导出... ,保存文件并切掉不相关的位.

The basics of the XML file can be determined by getting as much of the required config done in the Task Scheduler GUI on your dev machine; then using Export... from the context menu, saving the file and chopping out the irrelevant bits.

给出了基本的XML结构:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2018-03-28T18:00:00Z</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Windows\System32\cmd.exe</Command>
      <Arguments>/c dir</Arguments>
    </Exec>
  </Actions>
</Task>

这里的重要元素是<StartBoundary/>–它定义了任务应开始运行的日期/时间以及(在基于时间的触发器的情况下)每天,每周等应运行的时间.

The important element here is <StartBoundary/> – it defines both the date/time from which tasks should start running and (in the case of time-based triggers) the time at which it should run each day, week, etc.

如果要取消选中跨时区同步: 您必须为开始边界使用一个时间值,该时间值与希望任务运行 local 时间一致,并且 not 不会以结尾 GMT + 0/UTC + 0/祖鲁时间指示器Z:

If you want Synchronize across timezones to be unchecked: You must use a time value for start boundary that is as per the local time that you want the task to run and does not end with the GMT+0/UTC+0/zulu-time indicator Z:

<StartBoundary>2018-03-28T18:00:00</StartBoundary>

以上内容每天应在当地时间18:00运行.

The above should run every day, at 18:00 local time.

如果要检查跨时区同步: 您必须根据您当地的时区以及时区使用的任何夏令时系统,自己计算所需开始时间的GMT + 0/UTC + 0/zulu时间,然后使用此时间值末尾包含Z指示符:

If you want Synchronize across timezones to be checked: You must calculate the GMT+0/UTC+0/zulu-time of the desired start time yourself, based on your local timezone and respective of any daylight-savings system your timezone uses, then use this time value and include the Z indicator at the end:

<StartBoundary>2018-03-28T18:00:00Z</StartBoundary>

以上内容每天应在世界标准时间18:00运行,无论当地时间如何.

The above should run every day, at 18:00 UTC, regardless of local time.

要注册上述任务: 在命令提示符下,您将发出:

To register the above task: From the command prompt, you would issue:

schtasks.exe /create /tn "My Task Name" /xml x:\pathto\taskdefinition.xml

(注册后无需保留任务定义文件;设置将复制到创建的任务中.)

(You do not need to keep the task definition file after you have registered it; the settings are copied to the created task.)

这里的困难可能在于创建XML文件—.围绕文件的编码可能有点挑剔(您可能需要尝试字节顺序标记),并且有些设置的组合使我无法正常运行(它们注册确定,但是正在运行的任务立即失败,并返回奇怪的返回码).您的里程可能会有所不同.

The difficulty here is probably in creating the XML file — it can be a little finicky around the encoding of the file (you may need to experiment with byte-order markers), and there are some combinations of settings that I have never been able to get to run properly (they register OK, but the running task instantly fails with a strange return code). Your mileage may vary.

我从未尝试过托管包装器,但是建议它还在后台生成XML.但是,它似乎使用XmlDateTimeSerializationMode.RoundtripKind作为其序列化方法(正确地,对于往返)将时区作为序列化的一部分.

I've never tried with the Managed Wrapper, but the source suggests it also generates the XML in the background. However, it appears to use XmlDateTimeSerializationMode.RoundtripKind as its serialization method, which (rightly, for round-tripping) includes the timezone as part of the serialization.

这使我认为它永远不会创建未选中跨时区同步的任务.实际上,这可能意味着,如果您可以为您的开始时间确定正确的时区后缀,则您可能不需要自己进行上述基于Z的计算.

This leads me to think that it will never create a task that has Synchronize across timezones unchecked. In fact, it may mean that, if you can determine the correct timezone suffix for your start time, you might not need to do that Z-based calculation above, yourself.

您可能可以提出功能请求,以基于布尔属性(例如:

You might be able to raise a feature request, to have this changed based on a boolean property, e.g.:

writer.WriteElementString("StartBoundary", 
                          System.Xml.XmlConvert.ToString(t.StartBoundary, 
                          System.Xml.XmlDateTimeSerializationMode.RoundtripKind));

成为:

writer.WriteElementString("StartBoundary", 
                          System.Xml.XmlConvert.ToString(t.StartBoundary, 
                          SynchronizeAcrossTimezones 
                              ? System.Xml.XmlDateTimeSerializationMode.RoundtripKind
                              : System.Xml.XmlDateTimeSerializationMode.Unspecified));

...但这不取决于我!

...but that's not up to me!

这篇关于使用具有“跨时区同步"的任务计划程序托管包装器来创建计划任务.选项已禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆