From c1979a1197216181627d744a8d0b6f0729bf06de Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Thu, 29 Jun 2023 20:01:54 +0200 Subject: [PATCH] Add code for enabling autologin --- scripts/Windows/OS/User.ps1 | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/Windows/OS/User.ps1 b/scripts/Windows/OS/User.ps1 index 6274e9ca..c1a744bd 100644 --- a/scripts/Windows/OS/User.ps1 +++ b/scripts/Windows/OS/User.ps1 @@ -1,4 +1,7 @@ . "$PSScriptRoot/../Scripts/Context.ps1"; +$preparedUsernameProperty = "AutoLoginUser"; +$preparedPasswordProperty = "AutoLoginPassword"; +$autoLoginTriggerProperty = "AutoLoginTrigger"; $uacDisablerTriggerProperty = "UACDisablerTrigger"; function New-PersonalUser([Context] $context) @@ -75,12 +78,24 @@ function Set-UACState([bool] $value) { function Enable-UACNextLogin([Context] $context) { Set-UACState $true; $tempTask = "PortValhalla Temp"; + $autoLoginTrigger = Get-Random; $uacDisablerTrigger = Get-Random; $key = Get-SystemPolicyKey; + $context.Set($autoLoginTriggerProperty, $autoLoginTrigger, "DWord"); $context.Set($uacDisablerTriggerProperty, $uacDisablerTrigger, "DWord"); $optionCollection = [System.Tuple[uint, string, string[]][]]@( + [System.Tuple]::Create( + $autoLoginTrigger, + "PortValhalla AutoLogin Setup", + @( + ". '$PSScriptRoot/../Scripts/Context.ps1';", + "`$context = [Context]::new();", + "`$username = `$context.Get('$preparedUsernameProperty');", + "`$password = `$context.Get('$preparedPasswordProperty');", + "`$context.SetAutologin(`$username, `$password);", + "`$context.Remove('$preparedPasswordProperty');")), [System.Tuple]::Create( $uacDisablerTrigger, "PortValhalla UAC Disabler", @@ -128,5 +143,7 @@ function Enable-PersonalUserAutologon([Context] $context) } } - $context.SetAutologin($context.UserName, $password); + $context.Set($preparedUsernameProperty, $context.UserName, "ExpandString"); + $context.Set($preparedUsernameProperty, $password, "ExpandedString"); + Write-EventLog -LogName Application -Source "Application" -EventId $context.Get($autoLoginTriggerProperty) -Message "This event was created by $env:Username"; }