-1

I would like to replace 'restart'; meaning, when I press restart I would like the computer to execute a script instead.

Is there maybe a restart file that runs when I press restart that I can edit or change? Maybe through group policy?

The reason I need this is because there are operations that I would like to execute before each shutdown/restart.

I have already exhausted the option of shutdown and logoff script via group policy.

user64860
  • 111
  • 5

1 Answers1

3

The best way to do this is to create a suitable event-triggered task. (This runs a script upon shutdown, rather than replacing it, which would be a bad idea.)

Open Event Viewer, and find the shutdown event that you want to trigger the task on (e.g. in the "Windows Logs"->"System" log, filter for Source "User32" and Event 1074). Now on the right-hand panel, you'll find an "Attach Task To This Event..." option; select this to bring up a "Create Basic Task Wizard" dialog.

This is the normal Task Scheduler dialog for creating basic tasks; fill it in as normal (you'll notice that you can't change the event details), selecting "Start a program" as the task to perform, and setting the script you wish to run. Finish the task, and edit it if you want to set more advanced properties.

Note that the example above will only work for user-triggered shutdowns (including those from scheduled tasks); if you have other forms of shutdown, you'll need to find an example of the corresponding events to create the task from. If you only have the log, source and event ID, you can export an existing event-triggered task to file, edit the (XML) file appropriately with the log, source and event ID, and import it back into Task Scheduler.

Pak
  • 919
  • 5
  • 10