0

I have a powershell script that normal runs as foreground process (i.e. an app, on my desktop in a powerhshell console)

The script is coded such that when ctrl+c is pressed it will go through an orderly shutdown and close.

The script is currently being run as a background process (i.e. no console), but I still need to make it go through an orderly shutdown when it closes. I need to be able to do one of two things....

  1. Modify the script to detect when task manager has killed it and do an orderly shutdown (same as when ctrl+c is used normally), OR
  2. Send the equivalent of a ctrl+c from task manager.
ConanTheGerbil
  • 677
  • 8
  • 21
  • 1
    You can't intercept and End Process sent from Task Manager, but End Task [will send](https://stackoverflow.com/a/12313209/503046) an event. – vonPryz Feb 17 '22 at 09:57
  • Check if running `taskkill` vs your process without force flag triggers your termination routine. If not, you should implement some means of receiving either Windows messages, or TCP/UDP packets (or pipes, or whatever other channel of message processing there is) to trigger graceful termination. – Vesper Feb 17 '22 at 11:52

0 Answers0