Recipe 10.14. 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

You can use the schtasks.exe command to delete a task. The following command deletes the task named Job1:

> schtasks /delete /tn Job1

Using Group Policy

You can't delete a task with Group Policy, but you can prevent it from being deleted. Here is where you can find that setting:

\Computer Configuration\     Administrative Templates\Windows Components\Task Scheduler \User Configuration\     Administrative Templates\Windows Components\Task Scheduler Prohibit Task Deletion

Using VBScript
' This code deletes a scheduled AT task. ' ------ SCRIPT CONFIGURATION ------ intJobID = <JID>               ' e.g. 1452 strComputer = "<HostName>"   ' 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

You can't use the applet to delete a task on a remote system. However, there is another option. By default, a Scheduled Tasks share is created on Windows XP, which contains the job files for each scheduled task. Simply browse to \\<HostName>\Scheduled Tasks and you should see the list of scheduled tasks on that system (if you have administrator privileges). From here you can right-click a task and select Delete.

Using a command-line interface

To delete a task from the command line, you need to know the task name. Unless you know it off the top of your head, you'll need to query the current scheduled tasks to find the name of the one you want to delete. See Recipe 10.13 for more on how to do that.

See Also

Recipe 10.9 for creating a scheduled task; Recipe 10.13 for listing the scheduled tasks; and MS KB 310424, "HOW TO: Work with Scheduled Tasks on Remote Computers in Windows XP"



Windows XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

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