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,45 +79,35 @@ 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 @(",
@( " $autoLoginTrigger,",
"{", " '$contextScript',",
" Invoke-Command { $((Get-AutoLoginScript)) } -ArgumentList @(", " '$preparedUsernameProperty',",
" $autoLoginTrigger,", " '$preparedPasswordProperty'",
" '$contextScript',", " )",
" '$preparedUsernameProperty',", "}"),
" '$preparedPasswordProperty'",
" )",
"}")))
[System.Tuple]::Create( [System.Tuple]::Create(
$uacDisablerTrigger, $uacDisablerTrigger,
$uacDisablerName, $uacDisablerName,
[string]::Join( "{",
"`n", " Invoke-Command { $((Get-UACDisablerScript)) } -ArgumentList @(",
@( " $uacDisablerTrigger,",
"{", " '$contextScript',",
" Invoke-Command { $((Get-UACDisablerScript)) } -ArgumentList @(", " '$autoLoginName',",
" $uacDisablerTrigger,", " '$uacDisablerName',",
" '$contextScript',", " '$autoLoginTriggerProperty',",
" '$autoLoginName',", " '$uacDisablerTriggerProperty'",
" '$uacDisablerName',", " )",
" '$autoLoginTriggerProperty',", "}"));
" '$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;