Fix oneshot task execution
This commit is contained in:
parent
f70cad941f
commit
270854f435
|
@ -49,7 +49,7 @@ $null = New-Module {
|
||||||
$action = New-ScheduledTaskAction -Execute "pwsh" -Argument (Get-StartupArguments);
|
$action = New-ScheduledTaskAction -Execute "pwsh" -Argument (Get-StartupArguments);
|
||||||
schtasks /Create /SC ONEVENT /EC $logName /MO "*[System[Provider[@Name='$logName'] and EventID=$($oneShotTrigger)]]" /TR cmd.exe /TN $tempTask;
|
schtasks /Create /SC ONEVENT /EC $logName /MO "*[System[Provider[@Name='$logName'] and EventID=$($oneShotTrigger)]]" /TR cmd.exe /TN $tempTask;
|
||||||
$trigger = (Get-ScheduledTask $tempTask).Triggers;
|
$trigger = (Get-ScheduledTask $tempTask).Triggers;
|
||||||
$principal = New-ScheduledTaskPrincipal -UserId (Get-SetupUser) -RunLevel Highest;
|
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest;
|
||||||
$task = New-ScheduledTask -Action $action -Principal $principal -Trigger $trigger;
|
$task = New-ScheduledTask -Action $action -Principal $principal -Trigger $trigger;
|
||||||
$null = Register-ScheduledTask -Force $oneShotTaskName -InputObject $task;
|
$null = Register-ScheduledTask -Force $oneShotTaskName -InputObject $task;
|
||||||
$null = Unregister-ScheduledTask -Confirm:$false $tempTask;
|
$null = Unregister-ScheduledTask -Confirm:$false $tempTask;
|
||||||
|
@ -93,6 +93,7 @@ $null = New-Module {
|
||||||
|
|
||||||
Start-Job {
|
Start-Job {
|
||||||
Wait-Event -SourceIdentifier $identifier;
|
Wait-Event -SourceIdentifier $identifier;
|
||||||
|
Wait-Event -SourceIdentifier $identifier;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue