1

In my program, after installing, I'm adding a task to the task scheduler using the following command :

schtasks.exe /create /xml "task.xml" /tn "MyTasks/Task1" /f

In order to properly uninstall the program, I want to be able to remove totally the task folder "MyTasks". I can selectively delete this task using this command, but the folder still exists in the end :

schtasks.exe /delete /tn "MyTasks/Task1" /f 

Is there a way to completely delete the folder ?

Thanks !

1
  • 1
    schtasks.exe /delete /tn "MyTasks\Task1" /f&&rd"MyTasks"? Commented Apr 28, 2020 at 20:27

2 Answers 2

4

This is a vbs file.

Set TS  = CreateObject("Schedule.Service")
TS.Connect("ComputerName")
Set RootFolder = TS.GetFolder("\")
RootFolder.DeleteFolder "MyTasks", 0

Substitute your computer name.

https://learn.microsoft.com/en-us/windows/win32/taskschd/taskfolder-deletefolder

Sign up to request clarification or add additional context in comments.

1 Comment

Scripting it seems to be the only way. Deleting the task folder in C:\Windows\System32\Tasks as suggested in the other answers does not remove the folder within Task Scheduler. A PowerShell variant would be $TS = New-Object -Com Schedule.Service; $TS.Connect("$($env:ComputerName)"); $RootFolder = $TS.GetFolder("\"); $RootFolder.DeleteFolder("MyTasks", 0)
2

There is a way to do this, but not using schtasks: schtasks is able to create a directory, if asked for, but when using schtasks it can delete a task entry within a directory, but it can't delete the directory itself. I can only advise you to find the directory on your computer and to perform an rmdir.

3 Comments

Where is the physical folder for scheduled tasks? To use rd or rmdir wouldn't a physical folder be required?
@NekoMusume Scheduled Tasks have been stored in different places over the years including the registry. The first scheduler is at (type at /? for help). These are upgraded to the current version when you upgrade Windows. Win 95 had System Agent and Task Scheduler 1 came in with Win 98 (auto upgrading System Agent tasks). Currently the tasks are XML files at C:\Windows\System32\Tasks.
schtasks can delete a task directory, but only if the directory is empty. So if you have "foo/bar/baz", you first delete "foo/bar/baz", then delete "foo/bar", then delete "foo".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.