I imported a scheduled task into Windows Task Scheduler yesterday and that had some incorrect XML because of which each time I’d open Task Scheduler it would throw the following error at me: The task XML contains too many nodes of the same type
. What does that mean? No idea! Going through the XML file I imported from, I noticed some errors. So perhaps that’s the reason.
Ok, so can I delete this task from Task Scheduler? Nope! Each time I open Task Scheduler I get the above error but I don’t get to see the task.
What about schtasks
? I can see the task through that but I can’t make any changes!
1 2 3 4 5 6 7 8 9 |
C:\>schtasks Folder: \ TaskName Next Run Time Status ======================================== ====================== =============== Test 02/03/2015 08:30:30 Ready C:\>schtasks /delete /tn "Test" ERROR: The specified task name "Test" does not exist in the system. |
I tried creating a new task to over-write the existing one, but schtasks
complains that the task already exists. (Update: While writing this post I came across the the /f
switch to schtasks /create
– maybe that would have helped?)
Finally here’s what I did.
I found that all the scheduled tasks are located in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks
. There are various subkeys here of a format {GUID}
. Within each of these there is a value of name Path
whose data portion contains the task name (with a folder name if the task is in a folder).
Apart from that we have HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\
which has subkeys corresponding to each task. Each of these subkeys has a value of name Id
whose data is the GUID found above.
I deleted the subkeys corresponding to this problem task from both the locations above. That helped as Task Scheduler stopped complaining when I opened it. And which schtasks
still shows the task, that just seems to be a skeleton of the actual thing:
1 2 3 4 5 6 |
C:\>schtasks Folder: \ TaskName Next Run Time Status ======================================== ====================== =============== Test N/A N/A |
Unfortunately I still can’t delete it via <code>schtasks</code>:
1 2 |
C:\>schtasks /delete /tn "Test" ERROR: The specified task name "Test" does not exist in the system. |
However, now I can overwrite this task. So I created a dummy task over-writing this one and then deleted it!
1 2 3 4 5 6 7 |
C:\>schtasks /create /tr calc.exe /sc daily /tn "Test" WARNING: The task name "Test" already exists. Do you want to replace it (Y/N)? Y SUCCESS: The scheduled task "Test" has successfully been created. C:\>schtasks /delete /tn "Test" WARNING: Are you sure you want to remove the task "Test" (Y/N)? Y SUCCESS: The scheduled task "Test" was successfully deleted. |
Update: While writing this post I discovered that c:\Windows\System32\Tasks
is where the XML files for tasks are stored. So it looks like if I had deleted the task from this folder – apart from the registry keys above – that should have taken care of it.
Hope this helps someone!