Created
April 13, 2023 16:53
-
-
Save 0scvr/7d1aaacb8b2bc86077a1151cd0e3d6df to your computer and use it in GitHub Desktop.
Powershell script to prevent Windows from sleeping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param([int]$minutes=60) # input param, 60 minutes if no value provided | |
$wsh = New-Object -ComObject WScript.Shell | |
$a = Get-Date # Current time | |
$b = $a.AddMinutes($minutes) # Target time | |
while ($a -lt $b) { | |
# Send Shift+F15 | |
$wsh.SendKeys('+{F15}') | |
Start-Sleep -seconds 240 # sleep for 4 minutes | |
$a = Get-Date | |
} | |
# Use it with: powershell.exe -file dontsleep.ps1 -minutes 20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment