From 2dbd1a9fed2c5daeb0562504056418191da36cba Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Thu, 29 Jun 2023 17:27:00 +0200 Subject: [PATCH] Reorder UAC disablement steps --- scripts/Windows/OS/User.ps1 | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/scripts/Windows/OS/User.ps1 b/scripts/Windows/OS/User.ps1 index 8c9b906d..f563519b 100644 --- a/scripts/Windows/OS/User.ps1 +++ b/scripts/Windows/OS/User.ps1 @@ -45,31 +45,13 @@ function New-PersonalUser([Context] $context) Restart-Computer; exit; } - elseif ((Get-UACState)) + elseif ((Get-LocalUser $context.AdminName)) { - Write-EventLog -LogName Application -Source "Application" -EventId $taskTrigger -Message "This event was created by $env:Username"; - - for ($i = 0; $i -lt $120; $i++) - { - if ((Get-UACState)) - { - break; - } - } - - if ((Get-UACState)) - { - Write-Error "UAC Could not be disabled!"; - Read-Host "Press enter to continue anyway"; - } - Enable-CurrentUserAutologon $context; - Write-Information "Removing Admin Account"; Get-CimInstance -ClassName "Win32_UserProfile" -Filter "SID = $((Get-LocalUser $context.AdminName).SID)" | Remove-CimInstance; - - Write-Host "Rebooting"; - $context.Reboot(); + Write-EventLog -LogName Application -Source "Application" -EventId $taskTrigger -Message "This event was created by $env:Username"; + exit; } }