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,
|
||||
$autoLoginName,
|
||||
@(
|
||||
"{",
|
||||
" Invoke-Command { $("$(Get-AutoLoginScript)" -split "[`r`n]" -join " ") } -ArgumentList @(",
|
||||
" $autoLoginTrigger,",
|
||||
" '$contextScript',",
|
||||
" '$preparedUsernameProperty',",
|
||||
" '$preparedPasswordProperty'",
|
||||
" )",
|
||||
"}")),
|
||||
". `"$PSScriptRoot/AutoLogin.ps1`"",
|
||||
" $autoLoginTrigger",
|
||||
" '$contextScript'",
|
||||
" '$preparedUsernameProperty'",
|
||||
" '$preparedPasswordProperty'")),
|
||||
[System.Tuple]::Create(
|
||||
$uacDisablerTrigger,
|
||||
$uacDisablerName,
|
||||
@(
|
||||
"{",
|
||||
" Invoke-Command { $("$(Get-UACDisablerScript)" -split "[`r`n]" -join " ") } -ArgumentList @(",
|
||||
" $uacDisablerTrigger,",
|
||||
" '$contextScript',",
|
||||
" '$autoLoginName',",
|
||||
" '$uacDisablerName',",
|
||||
" '$autoLoginTriggerProperty',",
|
||||
" '$uacDisablerTriggerProperty'",
|
||||
" )",
|
||||
"}")));
|
||||
". `"$PSScriptRoot/UACDisabler.ps1`"",
|
||||
" $uacDisablerTrigger",
|
||||
" '$contextScript'",
|
||||
" '$autoLoginName'",
|
||||
" '$uacDisablerName'",
|
||||
" '$autoLoginTriggerProperty'",
|
||||
" '$uacDisablerTriggerProperty'")));
|
||||
|
||||
foreach ($options in $optionCollection) {
|
||||
$action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument (
|
||||
[string]::Join(" ", @("-c") + ($options.Item3)));
|
||||
$action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument ((@("-c") + $options.Item3) -join " ");
|
||||
|
||||
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;
|
||||
|
|
|
@ -1,20 +1,13 @@
|
|||
#!/bin/pwsh
|
||||
param(
|
||||
[int]$EventID,
|
||||
[string]$PreparedUsernameProperty,
|
||||
[string]$PreparedSecretProperty
|
||||
);
|
||||
|
||||
. "$PSScriptRoot/../../Scripts/Context.ps1";
|
||||
|
||||
function Get-AutoLoginScript() {
|
||||
return {
|
||||
param(
|
||||
[int]$EventID,
|
||||
[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";
|
||||
};
|
||||
}
|
||||
$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
|
||||
param (
|
||||
[int]$EventID,
|
||||
[string]$ContextScriptPath,
|
||||
[string]$AutoLoginTaskName,
|
||||
[string]$UACDisablerTaskName,
|
||||
[string]$AutoLoginTriggerProperty,
|
||||
[string]$UACDisablerTriggerProperty
|
||||
);
|
||||
|
||||
. "$PSScriptRoot/../../Scripts/Context.ps1";
|
||||
|
||||
function Get-UACDisablerScript() {
|
||||
return {
|
||||
param (
|
||||
[int]$EventID,
|
||||
[string]$ContextScriptPath,
|
||||
[string]$AutoLoginTaskName,
|
||||
[string]$UACDisablerTaskName,
|
||||
[string]$AutoLoginTriggerProperty,
|
||||
[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;
|
||||
};
|
||||
}
|
||||
$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