How to make the power button show a prompt in Windows 10

I dual-boot between Xubuntu and Windows 10. In Xubuntu, when I press the power button, a dialog pops up with buttons for shut down, restart, etc. I frequently use this to restart the computer, but I also use it when I want to shut it down, and I'd like to have the same thing in Windows, because (1) I keep pressing the power button out of habit instead of using the menus, and (2) like pushing the power button and then pushing an option on my touchscreen a lot better than pushing Windows+X->U->U, mostly because U (Shutdown) and I (Sign Out) are right next to each other, which leads to some mistakes when I'm trying to hastily shut down at the end of class.

I know how to change what the power buttons do from the Control Panel, but is there any way I can set the power button to prompt me for what I want to do every time I push it?

Or, better yet, is there any way to override the control panel's settings and make the power button launch an arbitrary executable or script that I could design myself (to match Xubuntu's menu)?


Solution 1:

There is no direct way to do this anymore. Windows XP used to have a feature in the Power control panel where you could set the power button to ask you what you want to do. However, that functionality was dropped in Windows Vista and later.

There is a way to simulate the behavior with local security policy, however.

  1. Launch the Local Group Policy Editor from the command line or your Run... dialog (gpedit.msc)
  2. Under Computer Configuration -> System, locate Display Shutdown Event Tracker and double-click it. Enable the policy and set the display mode to Always (screenshots below)

enter image description here

enter image description here

With this policy enabled, Windows will prompt you for the reason you are shutting down the computer. Not exactly a friendly "Do you want to shut down" box, but it does provide a backstop for when you hit the power button.

Solution 2:

I have spent some time trying all sorts of solutions that used to work, but which do not work any more in Windows 10 :

  • Shutdown script which does shutdown /a
  • AutoEndTasks with HungAppTimeout
  • AutoHotkey to intercept these events (examples: thread1, thread2)

None of them did any good.

Conclusion: There is no way to intercept or abort the Power button. Once it is pressed it is end-game.

The only solution I could find is:

  1. Set the Power button to do nothing :
    In Power Options -> Change plan settings -> Change advanced power settings -> Power buttons and lid -> Settings -> Do nothing.
  2. To really turn off the computer, use the Start Menu or create a desktop shortcut.
    For emergencies only use a long press on the Power button (all changes to open documents will be lost and there is a tiny danger to the health of the system files).