我创建了一个Windows任务,并计划每1小时运行一次。
任务运行的每一个小时,但我得到一个警告Task Scheduler did not launch task "\Sample Task" because computer is running on batteries. User Action: If launching the task on batteries is required, change the respective flag in the task configuration.
和任务退出前成熟。
我正在使用SCHTASKS.exe来创建任务,因为我需要创建从表单中获取用户输入的任务。
使用命令我想删除电源选项。这可能吗?
正如您可能已经观察到的那样,schtasks.exe
不提供命令行开关来切换电源设置。
你基本上有两个解决方案:
<Settings>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
</Settings>
ITaskSettings::DisallowStartIfOnBatteries
property设置为所需值的代码。简单。使用向导创建任务,然后配置所有内容禁用交流电源,然后将其导出到XML,然后编辑XML并删除线作者和准备就绪可以在任何计算机上使用和导入AC关闭和其他设置完好无损
schtasks / create / xml“&”edited.xml“&”/ tn nameTask / f“
最简单的方法可能是切换到PowerShell。有New-ScheduledTaskSettingsSet
,有一个-AllowStartIfOnBatteries
parameter。