Delete all scheduled jobs on a machine

  • Thread starter Thread starter Julian
  • Start date Start date
J

Julian

Can anyone provide me with some sample c# code for deleting all
scheduled jobs on a machine?

Thanks
 
Use Process.Start to start schtask.exe.
....
Process.Start(schtasks.exe", "/delete /tn * /f")
....

Willy.
 
Thanks Willy -

I was thinking of using something like the Win32_ScheduledJob class but
this seems to work. Is there anyway I could check for a return type to
ensure the deletion works?

Julian
 
Julian said:
Thanks Willy -

I was thinking of using something like the Win32_ScheduledJob class but
this seems to work. Is there anyway I could check for a return type to
ensure the deletion works?

Julian

Yes, call WaitForExit and get the Exit code, Exit 0 means success all else
means failed.
Win32_ScheduledJob can only be used with jobs created by Win32_ScheduledJob,
if this is your case you can query all jobs and delete each individual using
the JobId.

Willy.
 
Back
Top