Is there a way in windows to detect the event of pressing the physical power button, and after detecting the event execute or run a batch file. I basically
want to run a batch file that reboots the computer once the power button is pressed
Asked
Active
Viewed 3,813 times
2
-
1You cannot detect a hard shutdown. There are events generated for a normal shutdown. See Executing a batch script on Windows shutdown – DavidPostill Jun 30 '16 at 14:38
-
Is there a way to track it being turned on? I had assumed that that was what the OP wanted. – Xavierjazz Jun 30 '16 at 15:20
-
1@Xavierjazz, no OS is loaded at the time the power button is pressed to turn it on. So if that was the meaning and the goal is to run something, it could be added to the startup sequence. – fixer1234 Jun 30 '16 at 15:43
-
I want to run a batch file that reboots the computer once the power button is pressed – Sarthak Bansal Jun 30 '16 at 15:44
-
Then shouldn't that be your original question? – Xavierjazz Jun 30 '16 at 17:16
-
yes sorry just updated it – Sarthak Bansal Jun 30 '16 at 17:36
-
What version(s) of Windows does this question relate to? – misha256 Jun 30 '16 at 19:07
-
Windows 10 for now – Sarthak Bansal Jun 30 '16 at 20:19
1 Answers
-1
You would need to know the scan code (section Power Saving) for the power button key. Once you have this, then you could use software like AutoHotkey to overwrite the behavior of the buttons scancode to execute a command or batch file once the button is pressed.
NotAdmin Dave
- 2,868