Call Scheduled Tasks using scripts
This commit is contained in:
parent
98acbc4817
commit
4c66d01f00
3 changed files with 42 additions and 62 deletions
|
@ -84,32 +84,25 @@ function Enable-UACNextLogin([Context] $context) {
|
||||||
$autoLoginTrigger,
|
$autoLoginTrigger,
|
||||||
$autoLoginName,
|
$autoLoginName,
|
||||||
@(
|
@(
|
||||||
"{",
|
". `"$PSScriptRoot/AutoLogin.ps1`"",
|
||||||
" Invoke-Command { $("$(Get-AutoLoginScript)" -split "[`r`n]" -join " ") } -ArgumentList @(",
|
" $autoLoginTrigger",
|
||||||
" $autoLoginTrigger,",
|
" '$contextScript'",
|
||||||
" '$contextScript',",
|
" '$preparedUsernameProperty'",
|
||||||
" '$preparedUsernameProperty',",
|
" '$preparedPasswordProperty'")),
|
||||||
" '$preparedPasswordProperty'",
|
|
||||||
" )",
|
|
||||||
"}")),
|
|
||||||
[System.Tuple]::Create(
|
[System.Tuple]::Create(
|
||||||
$uacDisablerTrigger,
|
$uacDisablerTrigger,
|
||||||
$uacDisablerName,
|
$uacDisablerName,
|
||||||
@(
|
@(
|
||||||
"{",
|
". `"$PSScriptRoot/UACDisabler.ps1`"",
|
||||||
" Invoke-Command { $("$(Get-UACDisablerScript)" -split "[`r`n]" -join " ") } -ArgumentList @(",
|
" $uacDisablerTrigger",
|
||||||
" $uacDisablerTrigger,",
|
" '$contextScript'",
|
||||||
" '$contextScript',",
|
" '$autoLoginName'",
|
||||||
" '$autoLoginName',",
|
" '$uacDisablerName'",
|
||||||
" '$uacDisablerName',",
|
" '$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 ((@("-c") + $options.Item3) -join " ");
|
||||||
[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";
|
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;
|
||||||
|
|
|
@ -1,20 +1,13 @@
|
||||||
#!/bin/pwsh
|
#!/bin/pwsh
|
||||||
. "$PSScriptRoot/../../Scripts/Context.ps1";
|
|
||||||
|
|
||||||
function Get-AutoLoginScript() {
|
|
||||||
return {
|
|
||||||
param(
|
param(
|
||||||
[int]$EventID,
|
[int]$EventID,
|
||||||
[string]$ContextScriptPath,
|
|
||||||
[string]$PreparedUsernameProperty,
|
[string]$PreparedUsernameProperty,
|
||||||
[string]$PreparedSecretProperty
|
[string]$PreparedSecretProperty
|
||||||
);
|
);
|
||||||
|
|
||||||
. "$ContextScriptPath";
|
. "$PSScriptRoot/../../Scripts/Context.ps1";
|
||||||
$context = [Context]::new();
|
$context = [Context]::new();
|
||||||
$userName = $context.Get($PreparedUsernameProperty);
|
$userName = $context.Get($PreparedUsernameProperty);
|
||||||
$password = $context.Get($PreparedSecretProperty);
|
$password = $context.Get($PreparedSecretProperty);
|
||||||
$context.SetAutologin($userName, $password);
|
$context.SetAutologin($userName, $password);
|
||||||
Write-EventLog -LogName Application -Source "Application" -EventId $EventID -Message "This event was created by $env:Username";
|
Write-EventLog -LogName Application -Source "Application" -EventId $EventID -Message "This event was created by $env:Username";
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
#!/bin/pwsh
|
#!/bin/pwsh
|
||||||
. "$PSScriptRoot/../../Scripts/Context.ps1";
|
|
||||||
|
|
||||||
function Get-UACDisablerScript() {
|
|
||||||
return {
|
|
||||||
param (
|
param (
|
||||||
[int]$EventID,
|
[int]$EventID,
|
||||||
[string]$ContextScriptPath,
|
[string]$ContextScriptPath,
|
||||||
|
@ -12,7 +8,7 @@ function Get-UACDisablerScript() {
|
||||||
[string]$UACDisablerTriggerProperty
|
[string]$UACDisablerTriggerProperty
|
||||||
);
|
);
|
||||||
|
|
||||||
. "$ContextScriptPath";
|
. "$PSScriptRoot/../../Scripts/Context.ps1";
|
||||||
$context = [Context]::new();
|
$context = [Context]::new();
|
||||||
Unregister-ScheduledTask -Confirm:$false $AutoLoginTaskName;
|
Unregister-ScheduledTask -Confirm:$false $AutoLoginTaskName;
|
||||||
Unregister-ScheduledTask -Confirm:$false $UACDisablerTaskName;
|
Unregister-ScheduledTask -Confirm:$false $UACDisablerTaskName;
|
||||||
|
@ -22,5 +18,3 @@ function Get-UACDisablerScript() {
|
||||||
$context.DeregisterNewUserReboot();
|
$context.DeregisterNewUserReboot();
|
||||||
Write-EventLog -LogName Application -Source "Application" -EventId $EventID -Message "This event was created by $env:Username";
|
Write-EventLog -LogName Application -Source "Application" -EventId $EventID -Message "This event was created by $env:Username";
|
||||||
Restart-Computer -Force;
|
Restart-Computer -Force;
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue