Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
    
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
add comment

migrated from stackoverflow.com Sep 22 '12 at 22:59

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

2 Answers

up vote 2 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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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