JSI Tip 9100. How can I script the deletion of Scheduled Tasks that are Never scheduled to run?


NOTE: Tip 4806 » Windows XP contains a full featured command-line scheduler.

NOTE: Tip 5335 » Can I use the Windows XP command line scheduler in Windows 2000?

NOTE: Tip 7524 » How do I use Schtasks.exe to schedule tasks in Windows Server 2003?

Using Schtasks.exe, I have scripted DelSchNever.bat to delete all tasks are Never scheduled to run again, and have a nul Status.

DelSchNever.bat contains:

@echo off
for /f "Tokens=1-3 Delims=," %%a in ('schtasks /Query /FO CSV /NH^|FIND "Never"') do (
 if %%b EQU "Never" If %%c EQU "" SCHTASKS /DELETE /F /TN %%a
)
I have also scripted SchDelSchNever.bat, which is designed to be scheduled to run when your computer starts. It wakes up every 15 minutes and calls DelSchNever.bat to delete tasks. Don't forget to uncheck the Stop the task if it runs for: box on the Settings tab.

SchDelSchNever.bat contains:

@echo off
:again
@ping -n 901 127.0.0.1>nul
call DelSchNever.bat
goto again



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish