Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I delete a scheduled task? 1

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
US
I've written code to schedule a task to run at a specific time via the Task Scheduler. I now want to be able to delete the task from the task scheduler.

I can't seem to get the following code to work. What's wrong with my syntax?

Code:
    Dim objShell As Object
 
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Exec ("schtasks /delete /tn ""MyTaskName""")
    Set objShell = Nothing
 
Hi FancyPrairie,

The reason I think that your delete is failing as the way you're currently using it the command prompt will ask the user if they're sure they want to delete the task, but the command window will close before the request is ever seen by the user.

If you pass the /f switch to schtasks that will forcefully delete the task and suppress warnings (even if the task is running). So to delete the task try:
Code:
objShell.Exec ("schtasks /delete /tn ""MyTaskName"" /f")
Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Glad I could help, thanks for the star [smile]

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top