Recipe 5.8. Deleting a Scheduled TaskProblemYou want to delete a scheduled task. SolutionUsing a graphical user interface
Using a command-line interfaceOn 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 DiscussionUsing a graphical user interfaceThe 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 interfaceIn 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 VBScriptYou can write a script to delete all scheduled tasks by combining the code in Recipe 5.9 with this code. See AlsoRecipe 5.7, Recipe 5.9, and MS KB 310424 (HOW TO: Work with Scheduled Tasks on Remote Computers in Windows XP) |