Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Windows 7 box has a list of scheduled tasks - > Default Windows tasks + Certain custom tasks that all start with a certain string. Previous code deleted all tasks with the command:

schtasks /Delete /TN * /F

Instead we want to retain the default Windows tasks, and selectively delete the tasks that start with a certain string say abctask1, abctask2. How to proceed further? Thanks!

share|improve this question

migrated from Sep 22 '12 at 22:59

This question came from our site for professional and enthusiast programmers.

Have you tried using something like schtasks /Delete /TN abctask* /F? – Jonah Bishop Sep 20 '12 at 13:56
Doesnt work. I think the * wildcard doesn't work as expected. – user1620230 Sep 20 '12 at 14:56
If the wildcard doesn't work properly in that manner, your best bet might be to obtain the list of tasks with the /query option, loop through them finding the ones that match your desired pattern, and kill them off using their full names. Something like a Perl script might be best for this kind of task. – Jonah Bishop Sep 20 '12 at 17:21
up vote 4 down vote accepted

Assuming your tasks are one word (e.g., abctask1, abctask2 - not "abc task 1"), this should work:

for /f %%x in ('schtasks /query ^| findstr abctask') do schtasks /Delete /TN %%x /F
share|improve this answer
I would imagine that find, being less than 1/4 the size of findstr would react faster. Also, both support the use of quotation marks to surround the search term (find requires them), doing that will allow finding tasks like the "abc task 1" you mentioned. – James K Sep 21 '12 at 6:32
Thanks Mark, well actually it did not accept %%x, I changed it to %x and it worked! :) Cheers! :) – user1620230 Sep 21 '12 at 13:47
@user1620230 I assumed you were running this in a batch file. The double-percents in %%x are required in a batch file, whereas %x is required at the command line. @JamesK, I think you'd be very hard pressed to find any real-world speed difference in find vs. findstr, particularly in something this small. :-) – Mark Sep 21 '12 at 17:28
Aha, got you :) Well yes ultimately it might be used in a batch script. Thanks for the info :) – user1620230 Sep 21 '12 at 19:49

If you want wildcard (*) to be used in your selection of tasks to delete, try using this simple batch command:

(sample only)

echo off
del %SystemDrive%\Windows\Tasks\Google*
del %SystemDrive%\Windows\Tasks\Facebook*
share|improve this answer

Mark's answer works fine as long as you have fairly short scheduled task names, but the default output of schtasks /query (table format) truncates the task names to 32 characters, which causes errors when trying to delete them.

If you need to deal with tasks that have longer names, I would recommend using list output format instead, which does not truncate:

for /f "tokens=2 delims=\" %%x in ('schtasks /query /fo:list ^| findstr abctask') do schtasks /Delete /TN %%x /F

If the tasks you want to delete have a common prefix, you can further refine the match from findstr:

for /f "tokens=2 delims=\" %%x in ('schtasks /query /fo:list ^| findstr ^^abctask') do schtasks /Delete /TN %%x /F
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .