1

When a user of mine clicks the 'Restart' button on their system (Windows 10 in an Active Directory environment) I would like a quick batch script to run BEFORE the restart takes place.

My thought is that if I could remap the restart button to run the batch script and then have the last line in that batch script run the restart command.

How can I make this happen... unfortunately almost all searches including the word "remap" are talking about remapping keyboard keys.

EDIT: I am aware that we can run a shutdown script... unfortunately, I only want to run this script on RESTART, not on shutdown. If there was a way to differentiate, that would effectively solve the problem as well.

Run5k
  • 16,044
  • 24
  • 51
  • 65
  • See this post: https://superuser.com/questions/773651/run-a-script-just-before-shutdown-or-reboot-on-windows-home-edition – Daril Alemán Mar 28 '18 at 18:19
  • 1
    This feels like an XY problem. Why exactly do you feel like you need to do this? – EBGreen Mar 28 '18 at 18:50
  • 1
    The solution to this problem is to disable the ability for the user to restart the machine by using a group policy and write a script that exists on the desktop, that the user uses instead. If this isn't acceptable then you will have to use a scheduled task, when the user is logging off, and run your script instead. – Ramhound Mar 28 '18 at 18:55
  • EBGreen - because we have something that needs to happen on startup before any startup scripts could run. (effectively, we need 'restart' to alter the boot process and the only way to do that is to restart in a certain way) – lowcrawler Mar 29 '18 at 15:06
  • @lowcrawler: what if the user shut down and then starts, don't you need to run it? – Máté Juhász Mar 29 '18 at 16:36
  • @Mate, Nope, only on restart. Effectively, we want to use a script to bypass a boot check when the user restarts, but still allows the check when they just shut down and then boot up normally. – lowcrawler Mar 30 '18 at 17:11

1 Answers1

1

On our Windows domains, we configure a GPO in the following location:

User Configuration\Administrative Templates\Start Menu and Taskbar

Within that hiearchry, we enable the following policy:

Remove and prevent access to the Shut Down, Restart, Sleep, and Hibernate commands  

Once configured, the Windows 10 Start menu button will only have the option to Sign out.

After that, you can copy your custom batch file to the Public desktop (%SystemDrive%\Users\Public\Desktop) to make it readily available to all users, ensuring that you have the restart command (shutdown /r /f /t 0) at the end of the sequence.

Run5k
  • 16,044
  • 24
  • 51
  • 65
  • I'm going to mark this as the answer, as it appears to be the only solution. However, it doesn't really solve the original problem. – lowcrawler Apr 16 '18 at 16:28