Fix broken scheduled tasks

This commit is contained in:
Manuel Thalmann 2024-03-23 00:10:12 +01:00
parent 5d914ce33f
commit b1d9915786

View file

@ -79,13 +79,10 @@ function Enable-UACNextLogin([Context] $context) {
$context.Set($autoLoginTriggerProperty, $autoLoginTrigger, "DWord"); $context.Set($autoLoginTriggerProperty, $autoLoginTrigger, "DWord");
$context.Set($uacDisablerTriggerProperty, $uacDisablerTrigger, "DWord"); $context.Set($uacDisablerTriggerProperty, $uacDisablerTrigger, "DWord");
$optionCollection = [System.Tuple[int, string, string][]]@( $optionCollection = [System.Tuple[int, string, string[]][]]@(
[System.Tuple]::Create( [System.Tuple]::Create(
$autoLoginTrigger, $autoLoginTrigger,
$autoLoginName, $autoLoginName,
[string]::Join(
"`n",
@(
"{", "{",
" Invoke-Command { $((Get-AutoLoginScript)) } -ArgumentList @(", " Invoke-Command { $((Get-AutoLoginScript)) } -ArgumentList @(",
" $autoLoginTrigger,", " $autoLoginTrigger,",
@ -93,13 +90,10 @@ function Enable-UACNextLogin([Context] $context) {
" '$preparedUsernameProperty',", " '$preparedUsernameProperty',",
" '$preparedPasswordProperty'", " '$preparedPasswordProperty'",
" )", " )",
"}"))) "}"),
[System.Tuple]::Create( [System.Tuple]::Create(
$uacDisablerTrigger, $uacDisablerTrigger,
$uacDisablerName, $uacDisablerName,
[string]::Join(
"`n",
@(
"{", "{",
" Invoke-Command { $((Get-UACDisablerScript)) } -ArgumentList @(", " Invoke-Command { $((Get-UACDisablerScript)) } -ArgumentList @(",
" $uacDisablerTrigger,", " $uacDisablerTrigger,",
@ -109,15 +103,11 @@ function Enable-UACNextLogin([Context] $context) {
" '$autoLoginTriggerProperty',", " '$autoLoginTriggerProperty',",
" '$uacDisablerTriggerProperty'", " '$uacDisablerTriggerProperty'",
" )", " )",
"}")))); "}"));
foreach ($options in $optionCollection) { foreach ($options in $optionCollection) {
$action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument ( $action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument (
[string]::Join( [string]::Join(" ", @("-c") + ($options.Item3)));
" ",
(
@("-c") +
($options.Item3 | ForEach-Object { $_.TrimEnd(";") + ";" }))));
schtasks /Create /SC ONEVENT /EC Application /MO "*[System[Provider[@Name='Application'] and EventID=$($options.Item1)]]" /TR cmd.exe /TN "$tempTask"; schtasks /Create /SC ONEVENT /EC Application /MO "*[System[Provider[@Name='Application'] and EventID=$($options.Item1)]]" /TR cmd.exe /TN "$tempTask";
$trigger = (Get-ScheduledTask $tempTask).Triggers; $trigger = (Get-ScheduledTask $tempTask).Triggers;