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 !

TmZn
  • 399
  • 5
  • 16
  • `schtasks.exe /delete /tn "MyTasks\Task1" /f`[`&&`](https://ss64.com/nt/syntax-redirection.html)[`rd`](https://ss64.com/nt/rd.html)`"MyTasks"`? – aschipfl Apr 28 '20 at 20:27

2 Answers2

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.

Dominique
  • 16,450
  • 15
  • 56
  • 112
  • Where is the physical folder for scheduled tasks? To use `rd` or `rmdir` wouldn't a physical folder be required? – Nico Nekoru Apr 28 '20 at 22:03
  • 1
    @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`. –  Apr 29 '20 at 01:15
2

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