So, I got a HP Elitebook 1040 G10 I5 13th gen 16/512GB SSD laptop, and among other things, I use it to play music while I work in my workshop (it’s super-portable and that’s its greatest strength for other normal use & work, but it’s often in the workshop 🙂 ). However, it would go to sleep when left unattended – even when plugged in!
Table Of Contents (T.O.C.):
- Standard Windows (11) power options
- Advanced System Unattended Sleep Timeout options
- If all else fails – a PowerShell script
I tried the usual Windows Power settings and that didn’t help.
What did the trick? Two things:
1. Standard Windows (11) power options
Control Panel\Hardware and Sound\Power Options
There, I chose “Balanced” instead of the default “HP Optimized (Modern Standby).
Then, I went to:
Control Panel\Hardware and Sound\Power Options\Edit Plan Settings
clicked the “Change advanced power settings” and set the computer to not go to sleep for hour(s) even when running on a battery (I set it to hybernate when the battery reaches 5%).
2. Advanced System Unattended Sleep Timeout options
Windows has a hidden setting called “System Unattended Sleep Timeout”. This setting determines how long the system waits before it goes to sleep after the last user interaction has occurred. Here’s how to adjust it:
- Right-click on the Start button and select Run.
- Type
regedit
and press Enter to open the Registry Editor. - Navigate to
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\PowerSettings\238C9FA8-0AAD-41ED-83F4-97BE242C8F20\7bc4a2f9-d8fc-4469-b07b-33eb785aaca0
- Double-click on Attributes.
- Change the value from
1
na2
i kliknite OK. - Zatvorite Registry Editor and go back to Power Options > Change plan settings > Change advanced power settings.
- The System Unattended Sleep Timeout option should now be visible under the “Sleep” category, allowing you to set it to 666 minutes. 🙂
That’s it.
3. If all else fails – a PowerShell script
I mostly use this to keep remote connections open when unattended:
# Useful references:
#
# https://superuser.com/questions/992511/emulate-a-keyboard-button-via-the-command-line
# https://ss64.com/vb/sendkeys.html
# https://social.technet.microsoft.com/Forums/windowsserver/en-US/96b339e2-e9da-4802-a66d-be619aeb21ac/execute-function-one-time-in-every-10-mins-in-windows-powershell?forum=winserverpowershell
# https://learn-powershell.net/2013/02/08/powershell-and-events-object-events/
#
# Future enhancements - use events rather than an infinite loop
$wsh = New-Object -ComObject WScript.Shell
while (1) {
# Send Shift+F15 - this is the least intrusive key combination I can think of and is also used as default by:
# http://www.zhornsoftware.co.uk/caffeine/
# Unfortunately the above triggers a malware alert on Sophos so I needed to find a native solution - hence this script...
$wsh.SendKeys('+{F15}')
Start-Sleep -seconds 59
}
Source:
https://gist.github.com/jamesfreeman959/231b068c3d1ed6557675f21c0e346a9c
If you get an error: “running scripts is disabled on this system,” this is how you fix it on Windows 11:
- Run the PowerShell as an administrator.
- Enter the following command:
Set-ExecutionPolicy RemoteSigned
If you wish to prevent yourself from making a mess by double-clicking an unreliable .ps1 file, you can disable running scripts afterwards by running the command:
Set-ExecutionPolicy Restricted
If you don’t want to risk with enabling scripts to run globally, you could run with a one-time exception for a particular script. Here’s how:
Say you’ve saved the script on this path:
C:\Utils\keep-alive-power-shell-script.ps1
The command to run from the PowerShell is:
powershell -ExecutionPolicy Bypass -File C:\Utils\keep-alive-power-shell-script.ps1
Stating the obvious:
If you are using this script to keep a remote connection running, you should leave the remote window active. The script simulates pressing SHIFT+F15, and if it’s not used in the remote window, the connection may close for non-activity.
Yes, there are other ways to keep connections live for longer, but depending on your domain access rights, they may not be available.
Last updated:
Originally published: