Allow registering multiple scheduled tasks
This commit is contained in:
parent
34859556f0
commit
e235d70bc0
1 changed files with 19 additions and 11 deletions
|
@ -75,17 +75,16 @@ function Set-UACState([bool] $value) {
|
||||||
function Enable-UACNextLogin([Context] $context) {
|
function Enable-UACNextLogin([Context] $context) {
|
||||||
Set-UACState $true;
|
Set-UACState $true;
|
||||||
$tempTask = "PortValhalla Temp";
|
$tempTask = "PortValhalla Temp";
|
||||||
$uacDisablerName = "PortValhalla UAC Disabler";
|
|
||||||
$uacDisablerTrigger = Get-Random;
|
$uacDisablerTrigger = Get-Random;
|
||||||
|
|
||||||
$key = Get-SystemPolicyKey;
|
$key = Get-SystemPolicyKey;
|
||||||
$context.Set($uacDisablerTriggerProperty, $uacDisablerTrigger, "DWord");
|
$context.Set($uacDisablerTriggerProperty, $uacDisablerTrigger, "DWord");
|
||||||
|
|
||||||
$action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument (
|
$optionCollection = [System.Tuple[uint, string, string[]][]]@(
|
||||||
[string]::Join(
|
[System.Tuple]::Create(
|
||||||
" ",
|
$uacDisablerTrigger,
|
||||||
|
"PortValhalla UAC Disabler",
|
||||||
@(
|
@(
|
||||||
"-c",
|
|
||||||
"Set-ItemProperty '$($key.PSPath)' -Name 'EnableLUA' -Value 0 -Type DWord;",
|
"Set-ItemProperty '$($key.PSPath)' -Name 'EnableLUA' -Value 0 -Type DWord;",
|
||||||
"Unregister-ScheduledTask -Confirm:`$false '$uacDisablerName';",
|
"Unregister-ScheduledTask -Confirm:`$false '$uacDisablerName';",
|
||||||
". '$PSScriptRoot/../Scripts/Context.ps1';",
|
". '$PSScriptRoot/../Scripts/Context.ps1';",
|
||||||
|
@ -93,12 +92,21 @@ function Enable-UACNextLogin([Context] $context) {
|
||||||
"`$context.DeregisterNewUserReboot();",
|
"`$context.DeregisterNewUserReboot();",
|
||||||
"Restart-Computer -Force;")));
|
"Restart-Computer -Force;")));
|
||||||
|
|
||||||
schtasks /Create /SC ONEVENT /EC Application /MO "*[System[Provider[@Name='Application'] and EventID=$uacDisablerTrigger]]" /TR cmd.exe /TN "$tempTask";
|
foreach ($options in $optionCollection) {
|
||||||
|
$action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument (
|
||||||
|
[string]::Join(
|
||||||
|
" ",
|
||||||
|
(
|
||||||
|
@("-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";
|
||||||
$trigger = (Get-ScheduledTask $tempTask).Triggers;
|
$trigger = (Get-ScheduledTask $tempTask).Triggers;
|
||||||
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -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 $uacDisablerName -InputObject $task;
|
$null = Register-ScheduledTask $options.Item2 -InputObject $task;
|
||||||
$null = Unregister-ScheduledTask -Confirm:$false $tempTask;
|
$null = Unregister-ScheduledTask -Confirm:$false $tempTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Enable-PersonalUserAutologon([Context] $context)
|
function Enable-PersonalUserAutologon([Context] $context)
|
||||||
|
|
Loading…
Reference in a new issue