Set the batch file to execute just before shutdown, avoiding a restart.
Set the batch file to execute just before shutdown, avoiding a restart.
It would be useful if you could tell us what steps you've taken so far and the result you received. The issue arises because running a script during shutdown causes the system to stop, leaving little time to act before the script is terminated. You might consider a script that prevents shutdown, performs necessary tasks, and then reschedules the shutdown.
Create a simple script that performs an action, followed by a shutdown command using a different shortcut each time.
You won’t be able to catch a shutdown signal. The safest method is to delete the shutdown choice from the power settings in the Start Menu and include a command at the end of your script to trigger the shutdown (shutdown /sg /t 0 /f)
I propose an alternative approach: replace the shutdown button connection directly to the motherboard with some external hardware. Create a device that mimics a specific key (such as the Lenovo Vantage button) or triggers a complicated hotkey sequence you won’t use daily. Set up a service that runs your batch file when it receives a command.