Refactor creation of scheduled task action

This commit is contained in:
Manuel Thalmann 2023-06-28 22:06:35 +02:00
parent c3d8e79fcf
commit 03086d1052

View file

@ -47,9 +47,13 @@ function Enable-UACNextLogin() {
$propertyName = "EnableLUA"; $propertyName = "EnableLUA";
$null = Set-ItemProperty "$keyPath" -Name "$propertyName" -Value 1; $null = Set-ItemProperty "$keyPath" -Name "$propertyName" -Value 1;
$action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument ("-c " + ` $action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument (
"Set-ItemProperty `"$keyPath`" -Name `"$propertyName`" -Value 0;" + ` [string]::Join(
"Unregister-ScheduledTask -Force $taskName;"); " ",
@(
"-c",
"Set-ItemProperty `"$keyPath`" -Name `"$propertyName`" -Value 0;",
"Unregister-ScheduledTask -Force $taskName;")));
$trigger = New-ScheduledTaskTrigger -AtLogOn; $trigger = New-ScheduledTaskTrigger -AtLogOn;
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest; $principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest;