Reputation: 11
Actually I need to delete any task that contain some particular string.
I use schtasks /query /v /fo list
to list all tasks and schtasks /delete /tn XX /f
to remove a specific task.
Right now after I listed all tasks, I have to use Ctrl + F to find the string and copy paste manually.
Is it possible to show only task name that contain specific string in Task To Run? or even I can delete all the related task in one shot.
Thanks.
Upvotes: 0
Views: 847
Reputation:
Set TS = CreateObject("Schedule.Service")
TS.Connect("DESKTOP-UCDGI39")
Set rootFolder = TS.GetFolder("\")
Set tasks = rootFolder.GetTasks(0)
If tasks.Count = 0 Then
Wscript.Echo "No tasks are registered."
Else
WScript.Echo "Number of tasks registered: " & tasks.Count
For Each Task In Tasks
A=Task.Name
A = A & " " & Task.NextRunTime
wscript.echo A
Next
End If
For more info and sample code https://learn.microsoft.com/en-us/windows/win32/taskschd/displaying-task-names-and-state--scripting-.
Upvotes: 1