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
|
||||||
|
param(
|
||||||
|
[int]$EventID,
|
||||||
|
[string]$PreparedUsernameProperty,
|
||||||
|
[string]$PreparedSecretProperty
|
||||||
|
);
|
||||||
|
|
||||||
. "$PSScriptRoot/../../Scripts/Context.ps1";
|
. "$PSScriptRoot/../../Scripts/Context.ps1";
|
||||||
|
$context = [Context]::new();
|
||||||
function Get-AutoLoginScript() {
|
$userName = $context.Get($PreparedUsernameProperty);
|
||||||
return {
|
$password = $context.Get($PreparedSecretProperty);
|
||||||
param(
|
$context.SetAutologin($userName, $password);
|
||||||
[int]$EventID,
|
Write-EventLog -LogName Application -Source "Application" -EventId $EventID -Message "This event was created by $env:Username";
|
||||||
[string]$ContextScriptPath,
|
|
||||||
[string]$PreparedUsernameProperty,
|
|
||||||
[string]$PreparedSecretProperty
|
|
||||||
);
|
|
||||||
|
|
||||||
. "$ContextScriptPath";
|
|
||||||
$context = [Context]::new();
|
|
||||||
$userName = $context.Get($PreparedUsernameProperty);
|
|
||||||
$password = $context.Get($PreparedSecretProperty);
|
|
||||||
$context.SetAutologin($userName, $password);
|
|
||||||
Write-EventLog -LogName Application -Source "Application" -EventId $EventID -Message "This event was created by $env:Username";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,26 +1,20 @@
|
||||||
#!/bin/pwsh
|
#!/bin/pwsh
|
||||||
|
param (
|
||||||
|
[int]$EventID,
|
||||||
|
[string]$ContextScriptPath,
|
||||||
|
[string]$AutoLoginTaskName,
|
||||||
|
[string]$UACDisablerTaskName,
|
||||||
|
[string]$AutoLoginTriggerProperty,
|
||||||
|
[string]$UACDisablerTriggerProperty
|
||||||
|
);
|
||||||
|
|
||||||
. "$PSScriptRoot/../../Scripts/Context.ps1";
|
. "$PSScriptRoot/../../Scripts/Context.ps1";
|
||||||
|
$context = [Context]::new();
|
||||||
function Get-UACDisablerScript() {
|
Unregister-ScheduledTask -Confirm:$false $AutoLoginTaskName;
|
||||||
return {
|
Unregister-ScheduledTask -Confirm:$false $UACDisablerTaskName;
|
||||||
param (
|
$context.SetUACState($false);
|
||||||
[int]$EventID,
|
$context.Remove($AutoLoginTriggerProperty);
|
||||||
[string]$ContextScriptPath,
|
$context.Remove($UACDisablerTriggerProperty);
|
||||||
[string]$AutoLoginTaskName,
|
$context.DeregisterNewUserReboot();
|
||||||
[string]$UACDisablerTaskName,
|
Write-EventLog -LogName Application -Source "Application" -EventId $EventID -Message "This event was created by $env:Username";
|
||||||
[string]$AutoLoginTriggerProperty,
|
Restart-Computer -Force;
|
||||||
[string]$UACDisablerTriggerProperty
|
|
||||||
);
|
|
||||||
|
|
||||||
. "$ContextScriptPath";
|
|
||||||
$context = [Context]::new();
|
|
||||||
Unregister-ScheduledTask -Confirm:$false $AutoLoginTaskName;
|
|
||||||
Unregister-ScheduledTask -Confirm:$false $UACDisablerTaskName;
|
|
||||||
$context.SetUACState($false);
|
|
||||||
$context.Remove($AutoLoginTriggerProperty);
|
|
||||||
$context.Remove($UACDisablerTriggerProperty);
|
|
||||||
$context.DeregisterNewUserReboot();
|
|
||||||
Write-EventLog -LogName Application -Source "Application" -EventId $EventID -Message "This event was created by $env:Username";
|
|
||||||
Restart-Computer -Force;
|
|
||||||
};
|
|
||||||
}
|
|
Loading…
Reference in a new issue