0

I have a Powershell script that runs a process undefinitely.

I want it to perform a few commands before the PC's shutdown.

Here is the process I would like :

  1. User clicks shutdown button
  2. Windows shows the black screen
  3. Windows displays my script as 'preventing shutdown'
  4. The script receives a signal saying the system has to shut down
  5. The script runs a few commands and then exits
  6. Windows detects nothing is preventing shutdown ans shuts down

Would that be possible ? Thanks in advance !

Silloky
  • 147
  • 13
  • 1
    Look up GPOs, there's an option for shutdown / logoff scripts instead. – vonPryz Jun 13 '23 at 12:23
  • @vonPryz thanks, but can a shutdown script interact with another currently-running script ? if so, how, can the main script receive the signal from the GPO ? – Silloky Jun 13 '23 at 12:25
  • 1
    You should [edit] the question itself and explain with more details what you are trying to [achieve](https://xyproblem.info/). Some kind of IPC is needed, what would do depends on the actual problem. – vonPryz Jun 13 '23 at 12:32
  • 1
    It sounds like you'll want to implement a [Windows Service](https://stackoverflow.com/questions/5202119/detect-shutdown-in-window-service) to host your PowerShell script... – Mathias R. Jessen Jun 13 '23 at 12:34

0 Answers0