SchTasks.exe to create a task folder

匆匆过客 提交于 2019-12-03 23:51:51

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

Ken White

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.)

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
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!