我们目前在我们的 server 2008 机器上的 Windows 任务计划程序中安排了数百个任务。有许多任务无限期地每半小时运行一次。有没有办法使用脚本来更改这些任务的触发器,以便它们只会每半小时 MF 运行一次?
2 回答
是的,如果您使用TaskService COM 对象。有关使用此对象的一些示例脚本,请参阅以下内容:
在 Windows XP/Server 2003 之后,使用 schtasks.exe 实用程序相当有限。
Here are the allowed options for /SC:
/SC allows for the following frequency schedules:
MINUTE: 1 - 1439 minutes.
HOURLY: 1 - 23 hours.
DAILY: 1 - 365 days.
WEEKLY: weeks 1 - 52. (/D MON,TUE,WED,THU,FRI,SAT,SUN)
ONCE: No modifiers.
ONSTART: No modifiers.
ONLOGON: No modifiers.
ONIDLE: No modifiers.
MONTHLY: 1 - 12, or FIRST, SECOND, THIRD, FOURTH, LAST, LASTDAY.**
I keep editing this because I'm not happy with my findings...
I have looked into the SCHTASKS and noticed that you cannot CHANGE for the schedule through CMD.
From technet.microsoft
Changes one or more of the following properties of a task.
- The program that the task runs (/tr).
- The user account under which the task runs (/ru).
- The password for the user account (/rp).
I am going to continue to do some research on this, and hopefully will edit this answer with a workable solution.
EDIT
If you look in C:\windows\system32\tasks you will find all of your scheduled tasks
They're not listed as XML, but they are indeed XML
What I think should be done is using either; VBS or C# application dig to each of the following Nodes
//Task/Triggers/CalendarTrigger to delete /ScheduleByDay and it's child node /DaysInterval
//Task/Triggers/CalendarTrigger to create the following:
<?xml version="1.0" encoding="UTF-16"?>
-<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task" version="1.2">
+<RegistrationInfo>
-<Triggers>
-<CalendarTrigger>
<StartBoundary>2013-03-13T15:20:00</StartBoundary>
<Enabled>true</Enabled>
-<ScheduleByWeek>
-<DaysOfWeek>
<Monday/>
<Tuesday/>
<Wednesday/>
<Thursday/>
<Friday/>
</DaysOfWeek>
<WeeksInterval>1</WeeksInterval>
</ScheduleByWeek>
</CalendarTrigger>
</Triggers>
If anyone can pick up and run with this - I don't think I'll be able to do much with this in the next week.