Last active
September 14, 2024 23:06
-
-
Save mesheets/e1904603ce97e19bdd5be9f097d48a70 to your computer and use it in GitHub Desktop.
Continually adust the active hours to prevent Windows from automatically rebooting
This file contains hidden or 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
| # Continually adust the active hours to prevent Windows from automatically rebooting | |
| # Based on https://superuser.com/a/1456571 and https://superuser.com/a/1208866 | |
| # From comment at https://superuser.com/a/1456571: Execute script from the web | |
| # NOTE: The "subshell" is needed because setup.ps1 exits when finished | |
| # powershell -Command { Invoke-RestMethod https://raw.githubusercontent.com/marcosbozzani/Win10ActiveHours/7a214576ee2681c3e677b6c017429934a2c8c7d2/setup.ps1 | Invoke-Expression } | |
| # Constants | |
| [int]$MaxActiveHours = 18 | |
| [string]$RegistryPath = 'HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings' | |
| [string]$StartValueName = 'ActiveHoursStart' | |
| [string]$EndValueName = 'ActiveHoursEnd' | |
| [string]$EnabledValueName = 'IsActiveHoursEnabled' | |
| # Variable Declarations | |
| [int]$StartHour = (Get-Date).Hour | |
| [int]$EndHour = $StartHour + $MaxActiveHours | |
| # Handle rollover | |
| if ($EndHour -ge 24) | |
| { | |
| $EndHour = $EndHour - 24 | |
| } | |
| Set-ItemProperty -Path $RegistryPath -Name $StartValueName -Value $StartHour | |
| Set-ItemProperty -Path $RegistryPath -Name $EndValueName -Value $EndHour | |
| #Set-ItemProperty -Path $RegistryPath -Name $EnabledValueName -Value 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment