Enable UAC during Microsoft Account login

This commit is contained in:
Manuel Thalmann 2023-06-28 11:48:08 +02:00
parent 1f82f78c7f
commit 412b23cfc2

View file

@ -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;
}