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";
$null = Set-ItemProperty "$keyPath" -Name "$propertyName" -Value 1;
$action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument ("-c " + `
"Set-ItemProperty `"$keyPath`" -Name `"$propertyName`" -Value 0;" + `
"Unregister-ScheduledTask -Force $taskName;");
$action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument (
[string]::Join(
" ",
@(
"-c",
"Set-ItemProperty `"$keyPath`" -Name `"$propertyName`" -Value 0;",
"Unregister-ScheduledTask -Force $taskName;")));
$trigger = New-ScheduledTaskTrigger -AtLogOn;
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest;