START here

Preventing HP Elitebook laptop from going to sleep while playing music unattended – Windows 11

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.):

  1. Standard Windows (11) power options
  2. Advanced System Unattended Sleep Timeout options
  3. 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%).

– T.O.C. –

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 na 2 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.

– T.O.C. –

3. If all else fails – a PowerShell script

I mostly use this to keep remote connections open when unattended:

# Useful references:
# 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:
  # Unfortunately the above triggers a malware alert on Sophos so I needed to find a native solution - hence this script...
  Start-Sleep -seconds 59


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:

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.

– T.O.C. –

Leave a Comment

Please use the forum for any comments or questions.

If you've found any errors or lacking information in the article(s) - please let me know by commenting on the BikeGremlin forum.
You can comment anonymously (by registering with any name/nickname), but I think it is good to publicly document all the article additions (and especially corrections) - even if their author chooses to remain anonymous.

Skip to content