5.8. Deleting a Scheduled Task

Problem

You want to delete a scheduled task.

Solution

Using a graphical user interface

  1. From the Control Panel, open the Scheduled Task applet.

  2. Right-click on the target task and select Delete.

  3. Click Yes to confirm.

Using a command-line interface

On Windows Server 2003, you can use the schtasks.exe command to delete a task. The following command deletes the task named At1:

> schtasks /delete /tn At1

On Windows 2000, you need to use the at.exe command. The following command deletes the job associated with ID 3:

> at 3 /delete

Using VBScript

' This code deletes a scheduled task.
' ------ SCRIPT CONFIGURATION ------
intJobID = <JID>               ' e.g., 1452
strComputer = "<ServerName>"   ' e.g., dns01 
' ------ END CONFIGURATION ---------
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objInstance = objWMI.Get("Win32_ScheduledJob.JobID=" & intJobID)
intRC = objInstance.Delete
if intRC <> 0 then
   Wscript.Echo "Failure deleting task id: " & intJobID
else 
   Wscript.Echo "Sucessfully deleted task id: " & intJobID
end if

Discussion

Using a graphical user interface

The only downside is that you can't use this applet to delete a task on a remote system. However, you can still delete scheduled tasks on a remote machine. By default, a Scheduled Tasks share is created on all Windows 2000 and Windows Server 2003 servers, which contains the job files for each scheduled task. Simply browse to \\ <SeverName> \Scheduled Tasks and you should see the list of scheduled tasks on ...

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.