diff --git a/scripts/Windows/OS/User.ps1 b/scripts/Windows/OS/User.ps1 index 5f733d4a..c7412946 100644 --- a/scripts/Windows/OS/User.ps1 +++ b/scripts/Windows/OS/User.ps1 @@ -34,8 +34,24 @@ function New-PersonalUser([Context] $context) Write-Host "Registering setup script for all new users"; $context.RegisterNewUserReboot(); + Enable-UACNextLogin; $context.RemoveAutologin(); Restart-Computer; exit; } } + +function Enable-UACNextLogin() { + $taskName = "PortValhalla" + $keyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"; + $propertyName = "EnableLUA"; + Set-ItemProperty "$keyPath" -Name "$propertyName" -Value 1; + + $action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument ("-c " + ` + "Set-ItemProperty `"$keyPath`" -Name `"$propertyName`" -Value 0;" + ` + "Unregister-ScheduledTask $taskName;"); + $trigger = New-ScheduledTaskTrigger -AtLogOn; + $principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest; + $task = New-ScheduledTask -Action $action -Principal $principal -Trigger $trigger; + Register-ScheduledTask $taskName $task; +}