0

I have a task that runs a program every 10 minutes to scan a directory, convert .doc to .pdf and relocate them to a different directory.

Unfortunately, the program cannot handle large amounts of winword.exe processes so it often stops in progress. When this happens, the .doc files continue to build and I have to manually move files so it's a bit time-consuming.

I wrote an exe (C:\Windows\System32\cmd.exe /k task kill /IM winword.exe /F) and dropped on the desktop. I use this to kill all winword.exe processes so it clears the system after I stop the Task, and restart the task again afterwards.

Essentially, just trying to use one function to END a task, run a script to kill winword.exe processes, and RUN a task once the processes are killed but not sure what function would be best to do this.

Thanks for any advice.

codewario
  • 19,553
  • 20
  • 90
  • 159
m.tobin
  • 11
  • 1
  • 3
  • 2
    Isn't the obvious solution to [limit the number](https://stackoverflow.com/a/49551035/2152082) of winword processes? – Stephan Nov 08 '19 at 15:08
  • Instead of a task every 10 minutes, maybe you could consider a single script with an infinite loop that just runs all the time. – avery_larry Nov 08 '19 at 15:27

1 Answers1

0

While the best solution here would be to limit how many winword processes run at once as part of the program as @Stephan mentioned, if you want to stop a scheduled task, kill all winword processes, and start the task again, you can do so as follows in a Powershell script:

Stop-ScheduledTask -TaskName "Name of Scheduled Task"
Get-Process winword | Stop-Process -Force
Start-ScheduledTask -TaskName "Name of Scheduled Task"

Documentation on Stop-ScheduledTask, Start-ScheduledTask, Get-Process, and Stop-Process can be found at the preceeding links.

codewario
  • 19,553
  • 20
  • 90
  • 159