Simple script to automatically hibernate your Windows computer (without asking) at a specified time
Since I sometimes stay on my computer way too late, I find it very helpful to force myself off of my computer at a certain time. Having my computer shut itself down automatically forces me to wrap up before the deadline. If I forget, it'll turn off right in my face. It's also helpful for when I go off my computer but forget to shut it down. It's very nice to not have to worry about shutting it down.
- Windows
- GCC C++ Compiler (in PATH)
- Download AutoHibernate.cpp
- Open the file into a text editor, such as Notepad
- Change hibernate hour and minute (military time)
- Open a command line (such as cmd or Powershell) and cd to the directory you have downloaded the script to
- Compile the script to an exe with this command:
g++ -o AutoHibernate.exe AutoHibernate.cpp -mwindows -lPowrprof
- Navigate to the created exe file in your file explorer (it will be placed in the same directory as the C++ file)
- Create a shortcut to this exe file, and place it in your startup folder (
C:\Users\%User%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
)
The script will automatically start itself next time you restart your computer.
Disclaimer: Your antivirus may scan the exe file. Allow it to scan, and feel free to put it into Virustotal.
If you need to stay on your computer late, you can cancel the script using this command:
taskkill /F /IM AutoHibernate.exe
However, be aware that this will keep it off until you either restart your computer or start it manually by double-clicking the exe file.