Allow the prevention of sleep mode

This commit is contained in:
Manuel Thalmann 2023-07-29 02:58:00 +02:00
parent 79d3fd4d2d
commit 3578bf6407
2 changed files with 16 additions and 0 deletions

View file

@ -14,6 +14,7 @@ function Invoke-WindowsInstallation([Context] $context)
$null = Enable-WindowsOptionalFeature -Online -All -FeatureName "NetFx3";
$context.PreventSleepMode();
. "$configPath/Windows/Install.ps1" $context;
. "$configPath/Explorer/Install.ps1" $context;
. "$configPath/OpenSSH/Install.ps1" $context;

View file

@ -370,10 +370,25 @@ class Context {
exit;
}
[void] PreventSleepMode() {
$performanceScheme = "8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c";
$currentScheme = [regex]::Match((powercfg /GETACTIVESCHEME), "Power Scheme GUID: ([0-9a-f-]) ").Groups[1].Value;
if ($currentScheme -ne $performanceScheme) {
$this.Set("Power Scheme", $currentScheme);
powercfg /S 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c;
}
}
[void] Cleanup() {
$this.DeregisterNewUserReboot();
$this.RemoveAutologin();
$this.SetUACState($true);
Remove-Item $($this.EnsureConfigKey().PSPath);
$originalScheme = $this.Get("Power Scheme");
if ($originalScheme) {
powercfg /S $originalScheme;
}
}
}