2

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.

  • Can you confirm if testtask1 exists once, more than once, or not at all with Get-ScheduledTask | Sort-Object TaskName? To be thorough, run in an elevated instance of PS – root Feb 11 '16 at 16:04
  • @root It doesn't show in the list. The relevant XML file doesn't show up in C:\Windows\System32\Tasks either. It did once, before the scheduled task executed and subsequently expired and the file was deleted. It won't show anymore. – Vinayak Feb 11 '16 at 16:12
  • Not that anyone should expect different results between schtasks and Get-ScheduledTask, but I think the format for the /TN parameter requires the full path to the task. Eg schtasks /query /FO LIST /TN \Microsoft\Windows\Wininet\CacheTask returns a result where schtasks /query /FO LIST /TN CacheTask does not. Also - just to be safe - if you're actually using calc.exe in your task and it is still running from when the task ran, close it. – root Feb 11 '16 at 16:33
  • 1
    You may have old testtask1 records in the TaskCache. I'd search for them here and delete any found: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks and HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree – root Feb 11 '16 at 19:48
  • 1
    @root That did it! Thank you so much! The deleted tasks were listed under HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree but not ..\Tasks and after removing the relevant keys schtasks.exe stopped complaining. I wonder if this is a bug or just something that's only affecting my system. Nevertheless, please post it as an answer so I can accept. – Vinayak Feb 11 '16 at 22:09
4

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.