Store scheduled task in separate scripts
This commit is contained in:
parent
d649525722
commit
ba058911e9
3 changed files with 49 additions and 20 deletions
|
@ -1,5 +1,8 @@
|
||||||
#!/bin/pwsh
|
#!/bin/pwsh
|
||||||
. "$PSScriptRoot/../Scripts/Context.ps1";
|
$contextScript = "$PSScriptRoot/../../Scripts/Context.ps1";
|
||||||
|
. "$PSScriptRoot/AutoLogin.ps1";
|
||||||
|
. "$PSScriptRoot/UACDisabler.ps1";
|
||||||
|
. "$contextScript";
|
||||||
$preparedUsernameProperty = "AutoLoginUser";
|
$preparedUsernameProperty = "AutoLoginUser";
|
||||||
$preparedPasswordProperty = "AutoLoginPassword";
|
$preparedPasswordProperty = "AutoLoginPassword";
|
||||||
$autoLoginTriggerProperty = "AutoLoginTrigger";
|
$autoLoginTriggerProperty = "AutoLoginTrigger";
|
||||||
|
@ -76,31 +79,15 @@ function Enable-UACNextLogin([Context] $context) {
|
||||||
$context.Set($autoLoginTriggerProperty, $autoLoginTrigger, "DWord");
|
$context.Set($autoLoginTriggerProperty, $autoLoginTrigger, "DWord");
|
||||||
$context.Set($uacDisablerTriggerProperty, $uacDisablerTrigger, "DWord");
|
$context.Set($uacDisablerTriggerProperty, $uacDisablerTrigger, "DWord");
|
||||||
|
|
||||||
$optionCollection = [System.Tuple[int, string, string[]][]]@(
|
$optionCollection = [System.Tuple[int, string, string][]]@(
|
||||||
[System.Tuple]::Create(
|
[System.Tuple]::Create(
|
||||||
$autoLoginTrigger,
|
$autoLoginTrigger,
|
||||||
$autoLoginName,
|
$autoLoginName,
|
||||||
@(
|
"{ $((Get-AutoLoginScript)) }.Invoke('$contextScript', '$preparedUsernameProperty', '$preparedPasswordProperty')")
|
||||||
". '$PSScriptRoot/../Scripts/Context.ps1';",
|
|
||||||
"`$context = [Context]::new();",
|
|
||||||
"`$username = `$context.Get('$preparedUsernameProperty');",
|
|
||||||
"`$password = `$context.Get('$preparedPasswordProperty');",
|
|
||||||
"`$context.SetAutologin(`$username, `$password);",
|
|
||||||
"`$context.Remove('$preparedUsernameProperty');",
|
|
||||||
"`$context.Remove('$preparedPasswordProperty');")),
|
|
||||||
[System.Tuple]::Create(
|
[System.Tuple]::Create(
|
||||||
$uacDisablerTrigger,
|
$uacDisablerTrigger,
|
||||||
$uacDisablerName,
|
$uacDisablerName,
|
||||||
@(
|
"{ $((Get-UACDisablerScript)) }.Invoke('$contextScript', '$autoLoginName', '$uacDisablerName', '$autoLoginTriggerProperty', '$uacDisablerTriggerProperty')"));
|
||||||
"Unregister-ScheduledTask -Confirm:`$false '$autoLoginName';",
|
|
||||||
"Unregister-ScheduledTask -Confirm:`$false '$uacDisablerName';",
|
|
||||||
". '$PSScriptRoot/../Scripts/Context.ps1';",
|
|
||||||
"`$context = [Context]::new();",
|
|
||||||
"`$context.SetUACState(`$false);",
|
|
||||||
"`$context.Remove('$autoLoginTriggerProperty');",
|
|
||||||
"`$context.Remove('$uacDisablerTriggerProperty');",
|
|
||||||
"`$context.DeregisterNewUserReboot();",
|
|
||||||
"Restart-Computer -Force;")));
|
|
||||||
|
|
||||||
foreach ($options in $optionCollection) {
|
foreach ($options in $optionCollection) {
|
||||||
$action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument (
|
$action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument (
|
||||||
|
|
18
scripts/Windows/OS/User/AutoLogin.ps1
Normal file
18
scripts/Windows/OS/User/AutoLogin.ps1
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/pwsh
|
||||||
|
. "$PSScriptRoot/../../Scripts/Context.ps1";
|
||||||
|
|
||||||
|
function Get-AutoLoginScript() {
|
||||||
|
return {
|
||||||
|
param(
|
||||||
|
[string]$ContextScriptPath,
|
||||||
|
[string]$PreparedUsernameProperty,
|
||||||
|
[string]$PreparedSecretProperty
|
||||||
|
);
|
||||||
|
|
||||||
|
. "$ContextScriptPath";
|
||||||
|
$context = [Context]::new();
|
||||||
|
$userName = $context.Get($PreparedUsernameProperty);
|
||||||
|
$password = $context.Get($PreparedSecretProperty);
|
||||||
|
$context.SetAutologin($userName, $password);
|
||||||
|
};
|
||||||
|
}
|
24
scripts/Windows/OS/User/UACDisabler.ps1
Normal file
24
scripts/Windows/OS/User/UACDisabler.ps1
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#!/bin/pwsh
|
||||||
|
. "$PSScriptRoot/../../Scripts/Context.ps1";
|
||||||
|
|
||||||
|
function Get-UACDisablerScript() {
|
||||||
|
return {
|
||||||
|
param (
|
||||||
|
[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();
|
||||||
|
Restart-Computer -Force;
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue