问题
Is there a command to create a Schedule task folder in Windows 2008? I am trying to use SchTasks.exe to create the tasks and would like to put these tasks under a task folder. Essentially, inside task scheduler, add a new folder and add multiple tasks underneath the folder. From UI there is an option to create a folder but not sure about command reference
Thanks in advance
回答1:
few trials and solved the problem; the key is using "\" in the task name. Sample schtask.exe command line,
schtasks /create /xml "MyTask.xml" /tn "My Task Folder\My New Task"
creates a new task folder My Task Folder and creates a new task My New Task under the new folder
If the task needs to get created under an existing folder, try
schtasks /create /xml "MyTask.xml" /tn "Existing Task Folder\My New Task"
creates a new task My New Task under an existing task folder Existing Task Folder
回答2:
There doesn't appear to be any way to do this via SchTasks.exe
. If you run SchTasks.exe /Create /?
at a command prompt, it shows you the available options. Creating a folder for the task doesn't show up as one of them, as far as I can see.
You might be able to do this via the ITaskScheduler
interface. See this question for a discussion of the difference, and a link to a library that encapsulates the interface. (I haven't seen the library and don't know anything about it; it just appears as the solution based on the accepted answer to the linked question.)
回答3:
It's an old thread but I found no answer elsewhere so I wrote a little powershell script which copies the task to a new folder and rewrites the UserId if wanted. Don't forget to delete the old tasks manually.
Get-ScheduledTask | ? {$_.Taskpath -ieq "\FROM"} | % {
$oTask = $_
[XML]$TaskXML = Export-ScheduledTask -TaskName $oTask.TaskName
#$TaskXML.GetElementsByTagName("UserId")[0].InnerText="SYSTEM"
Register-ScheduledTask -TaskName $oTask.TaskName -TaskPath "\TO" -Xml $TaskXML.InnerXML
}
来源:https://stackoverflow.com/questions/9795560/schtasks-exe-to-create-a-task-folder