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($uacDisablerTriggerProperty, $uacDisablerTrigger, "DWord");
$optionCollection = [System.Tuple[int, string, string][]]@(
$optionCollection = [System.Tuple[int, string, string[]][]]@(
[System.Tuple]::Create(
$autoLoginTrigger,
$autoLoginName,
[string]::Join(
"`n",
@(
"{",
" Invoke-Command { $((Get-AutoLoginScript)) } -ArgumentList @(",
" $autoLoginTrigger,",
" '$contextScript',",
" '$preparedUsernameProperty',",
" '$preparedPasswordProperty'",
" )",
"}")))
"{",
" Invoke-Command { $((Get-AutoLoginScript)) } -ArgumentList @(",
" $autoLoginTrigger,",
" '$contextScript',",
" '$preparedUsernameProperty',",
" '$preparedPasswordProperty'",
" )",
"}"),
[System.Tuple]::Create(
$uacDisablerTrigger,
$uacDisablerName,
[string]::Join(
"`n",
@(
"{",
" Invoke-Command { $((Get-UACDisablerScript)) } -ArgumentList @(",
" $uacDisablerTrigger,",
" '$contextScript',",
" '$autoLoginName',",
" '$uacDisablerName',",
" '$autoLoginTriggerProperty',",
" '$uacDisablerTriggerProperty'",
" )",
"}"))));
"{",
" Invoke-Command { $((Get-UACDisablerScript)) } -ArgumentList @(",
" $uacDisablerTrigger,",
" '$contextScript',",
" '$autoLoginName',",
" '$uacDisablerName',",
" '$autoLoginTriggerProperty',",
" '$uacDisablerTriggerProperty'",
" )",
"}"));
foreach ($options in $optionCollection) {
$action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument (
[string]::Join(
" ",
(
@("-c") +
($options.Item3 | ForEach-Object { $_.TrimEnd(";") + ";" }))));
[string]::Join(" ", @("-c") + ($options.Item3)));
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;