Task Scheduler won't allow re-use of task names from older, auto-deleted tasks that were created with the /Z switch
While trying to get this to work I created several scheduled tasks with the /Z
switch which, according to documentation is...
A value that marks the task to be deleted after its final run.
I was able to create scheduled tasks that were automatically deleted after they expired but I couldn't create new tasks with the same name thereafter. Here's a partial log of the commands I used:
C:\WINDOWS\system32>schtasks /create /TN testtask1 /TR calc.exe /SC ONCE /ST 20:06 SUCCESS: The scheduled task "testtask1" has successfully been created. C:\WINDOWS\system32>schtasks /create /TN testtask1 /TR calc.exe /SC ONCE /ST 20:07 /F SUCCESS: The scheduled task "testtask1" has successfully been created. C:\WINDOWS\system32>schtasks /create /TN testtask1 /TR calc.exe /SC ONCE /ST 20:08 /F /Z ERROR: The task XML is missing a required element or attribute. (40,4):EndBoundary: C:\WINDOWS\system32>schtasks /create /TN testtask1 /TR calc.exe /SC MINUTE /MO 1 /ST 20:09 /ET 20:11 /F /Z SUCCESS: The scheduled task "testtask1" has successfully been created. C:\WINDOWS\system32>schtasks /query /TN testtask1 Folder: \ TaskName Next Run Time Status ======================================== ====================== =============== testtask1 11-02-2016 20:11:00 Ready C:\WINDOWS\system32>schtasks /query /TN testtask1 ERROR: The system cannot find the file specified. C:\WINDOWS\system32>schtasks /create /TN testtask1 /TR calc.exe /SC MINUTE /MO 1 /ST 20:12 /ET 20:14 /F /Z ERROR: The system cannot find the file specified. C:\WINDOWS\system32>schtasks /create /TN testtask1 /TR calc.exe /SC MINUTE /MO 1 /ST 20:12 /ET 20:14 /Z WARNING: The task name "testtask1" already exists. Do you want to replace it (Y/N)? y ERROR: The system cannot find the file specified.
I'm using Windows 10 (Build 10586.104) and I haven't tested this on older Windows versions so I'm not sure if this issue is specific to my system. I also can not use the GUI interface (taskschd.msc
) to create scheduled tasks with previously used names.
On @root's suggestion, I tried running Unregister-ScheduledTask -TaskName testtask1 -Confirm:$false
in PowerShell but that got me this error:
Unregister-ScheduledTask : No MSFT_ScheduledTask objects found with property 'TaskName' equal to 'testtask1'. Verify the value of the property and retry.
I also ran fsutil resource setautoreset true c:\
and rebooted Windows as recommended by aikitsupport.com but that didn't help either.
PS If you can think of a better question title, feel free to edit it.
Solution 1:
Delete non-valid entries from the TaskCache. The TaskCache is normally maintained automatically, in this case some entries were not removed automatically when the task was deleted.
Search in registry and manually delete any keys that contain the non-valid scheduled task name that are found in:
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks
and
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree
This will allow reuse of the task name.
Other users with this scenario may also have to delete entries found in C:\Windows\System32\Tasks
containing the task name, although in this case, you noticed these had already been deleted.