Recipe5.8.Deleting a Scheduled Task


Recipe 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.JobFailure 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 that server (if you have administrator privileges). From here you can right-click a task and select Delete.

Using a command-line interface

In the command-line solutions, you need to know the task name (for schtasks) or the job ID (for at) in order to delete a task. Unless you know it off the top of your head, more than likely you'll need to query the current scheduled tasks to find the name or ID of the one you want to delete. See Recipe 5.9 for more on how to do that.

Using VBScript

You can write a script to delete all scheduled tasks by combining the code in Recipe 5.9 with this code.

See Also

Recipe 5.7, Recipe 5.9, and MS KB 310424 (HOW TO: Work with Scheduled Tasks on Remote Computers in Windows XP)



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net