From 4a7fc5521cc95eb01570d3b303a81642f85e55a8 Mon Sep 17 00:00:00 2001 From: he3als <65787561+he3als@users.noreply.github.com> Date: Tue, 11 Jul 2023 22:41:33 +0100 Subject: [PATCH 1/3] fix: kill Edge first & -Setup arg --- .../Atlas/1. Software/Remove Edge.ps1 | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Executables/Atlas/1. Software/Remove Edge.ps1 b/src/Executables/Atlas/1. Software/Remove Edge.ps1 index 07afeac6ba..d2ebf44478 100644 --- a/src/Executables/Atlas/1. Software/Remove Edge.ps1 +++ b/src/Executables/Atlas/1. Software/Remove Edge.ps1 @@ -1,6 +1,6 @@ [CmdletBinding()] param ( - [Switch]$RemoveAllEdge + [Switch]$Setup ) $ProgressPreference = "SilentlyContinue" @@ -12,6 +12,22 @@ function PauseNul ($message = "Press any key to continue... ") { function RemoveEdgeChromium { $baseKey = "HKLM:\SOFTWARE\WOW6432Node\Microsoft" + + # kill Edge + $ErrorActionPreference = 'SilentlyContinue' + + Get-Process -Name MicrosoftEdgeUpdate | Stop-Process -Force + Get-Process -Name msedge | Stop-Process -Force + + $services = @( + 'edgeupdate', + 'edgeupdatem', + 'MicrosoftEdgeElevationService' + ) + + foreach ($service in $services) {Stop-Service -Name $service -Force} + + $ErrorActionPreference = 'Continue' # check if 'experiment_control_labels' value exists and delete it if found $keyPath = Join-Path -Path $baseKey -ChildPath "EdgeUpdate\ClientState\{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}" @@ -75,10 +91,15 @@ function UninstallAll { } } -if ($RemoveAllEdge) { - $removeWebView = $true +# AppX is not removed as it's handled by AME Wizard +if ($Setup) { $removeData = $true - UninstallAll + Write-Warning "Uninstalling Edge Chromium..." + RemoveEdgeChromium + Write-Warning "Uninstalling Edge WebView..." + RemoveWebView + Write-Warning "The AppX Edge needs to be removed by AME Wizard..." + exit } if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) { @@ -88,8 +109,7 @@ if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdent $removeWebView = $false $removeData = $true while (!($continue)) { - cls - Write-Host "This script will remove Microsoft Edge, as once you install it, you can't normally uninstall it. + cls; Write-Host "This script will remove Microsoft Edge, as once you install it, you can't normally uninstall it. Major credit to ave9858: https://gist.github.com/ave9858/c3451d9f452389ac7607c99d45edecc6`n" -ForegroundColor Yellow if ($removeWebView) {$colourWeb = "Green"; $textWeb = "Selected"} else {$colourWeb = "Red"; $textWeb = "Unselected"} From 458237848d50328f4fd6783fd20eb3a591daa95c Mon Sep 17 00:00:00 2001 From: he3als <65787561+he3als@users.noreply.github.com> Date: Tue, 11 Jul 2023 23:34:08 +0100 Subject: [PATCH 2/3] feat(edge): make compatible with TI (non-AppX) --- .../Atlas/1. Software/Remove Edge.ps1 | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/Executables/Atlas/1. Software/Remove Edge.ps1 b/src/Executables/Atlas/1. Software/Remove Edge.ps1 index d2ebf44478..8a5e53d720 100644 --- a/src/Executables/Atlas/1. Software/Remove Edge.ps1 +++ b/src/Executables/Atlas/1. Software/Remove Edge.ps1 @@ -10,7 +10,26 @@ function PauseNul ($message = "Press any key to continue... ") { $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') | Out-Null } +# removing Edge Chromium & WebView is meant to be compatible with TrustedInstaller for AME Wizard +# running the uninstaller as TrustedInstaller causes shortcuts and other things not to be removed properly +function RunAsScheduledTask { + [CmdletBinding()] + param ( + [String]$Command + ) + $user = (Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -ExpandProperty UserName) -replace ".*\\" + $action = New-ScheduledTaskAction -Execute "$env:windir\System32\cmd.exe" -Argument "/c $Command" + $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries + $title = "RemoveEdge $(Get-Random -minimum 9999999999)" + Register-ScheduledTask -TaskName $title -Action $action -Settings $settings -User $user -RunLevel Highest -Force | Start-ScheduledTask | Out-Null + Unregister-ScheduledTask -TaskName $title -Confirm:$false | Out-Null +} + function RemoveEdgeChromium { + [CmdletBinding()] + param ( + [String]$AsTask + ) $baseKey = "HKLM:\SOFTWARE\WOW6432Node\Microsoft" # kill Edge @@ -47,8 +66,11 @@ function RemoveEdgeChromium { # uninstall Edge $uninstallKeyPath = Join-Path -Path $baseKey -ChildPath "Windows\CurrentVersion\Uninstall\Microsoft Edge" if (Test-Path $uninstallKeyPath) { - $uninstallString = (Get-ItemProperty -Path $uninstallKeyPath).UninstallString - Start-Process cmd.exe "/c $uninstallString --force-uninstall" -WindowStyle Hidden + $uninstallString = (Get-ItemProperty -Path $uninstallKeyPath).UninstallString + " --force-uninstall" + # create a scheduled task as current user so that it works properly with TI perms + if ($AsTask) {RunAsScheduledTask -Command $uninstallString} else { + Start-Process cmd.exe "/c $uninstallString" -WindowStyle Hidden + } } # remove user data @@ -66,6 +88,7 @@ function RemoveEdgeAppX { if (Test-Path "$pattern") { reg delete "HKLM$appxStore\InboxApplications\$edgeAppXKey" /f | Out-Null } # make the Edge AppX able to uninstall and uninstall + $user = (Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -ExpandProperty UserName) -replace ".*\\" $SID = (New-Object System.Security.Principal.NTAccount($env:USERNAME)).Translate([Security.Principal.SecurityIdentifier]).Value New-Item -Path "HKLM:$appxStore\EndOfLife\$SID\Microsoft.MicrosoftEdge_8wekyb3d8bbwe" -Force | Out-Null Get-AppxPackage -Name Microsoft.MicrosoftEdge | Remove-AppxPackage | Out-Null @@ -73,10 +96,16 @@ function RemoveEdgeAppX { } function RemoveWebView { + [CmdletBinding()] + param ( + [String]$AsTask + ) $webviewUninstallKeyPath = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView" if (Test-Path $webviewUninstallKeyPath) { - $webviewUninstallString = (Get-ItemProperty -Path $webviewUninstallKeyPath).UninstallString - Start-Process cmd.exe "/c $webviewUninstallString --force-uninstall" -WindowStyle Hidden + $webviewUninstallString = (Get-ItemProperty -Path $webviewUninstallKeyPath).UninstallString + " --force-uninstall" + if ($AsTask) {RunAsScheduledTask -Command $webviewUninstallString} else { + Start-Process cmd.exe "/c $uninstallString" -WindowStyle Hidden + } } } @@ -95,9 +124,9 @@ function UninstallAll { if ($Setup) { $removeData = $true Write-Warning "Uninstalling Edge Chromium..." - RemoveEdgeChromium + RemoveEdgeChromium -AsTask Write-Warning "Uninstalling Edge WebView..." - RemoveWebView + RemoveWebView -AsTask Write-Warning "The AppX Edge needs to be removed by AME Wizard..." exit } @@ -106,6 +135,13 @@ if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdent Start-Process PowerShell "-NoProfile -ExecutionPolicy Unrestricted -File `"$PSCommandPath`"" -Verb RunAs; exit } +if ($(whoami /user | Select-String "S-1-5-18") -ne $null) { + Write-Host "This script can't be ran as TrustedInstaller or SYSTEM." + Write-Host "Please relaunch this script under a regular admin account.`n" + PauseNul "Press any key to exit... " + exit 1 +} + $removeWebView = $false $removeData = $true while (!($continue)) { From a4e856e74da4ebef939bf28274538535e0477074 Mon Sep 17 00:00:00 2001 From: he3als <65787561+he3als@users.noreply.github.com> Date: Tue, 11 Jul 2023 23:35:33 +0100 Subject: [PATCH 3/3] fix(edge): string -> switch --- src/Executables/Atlas/1. Software/Remove Edge.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Executables/Atlas/1. Software/Remove Edge.ps1 b/src/Executables/Atlas/1. Software/Remove Edge.ps1 index 8a5e53d720..56d1610eee 100644 --- a/src/Executables/Atlas/1. Software/Remove Edge.ps1 +++ b/src/Executables/Atlas/1. Software/Remove Edge.ps1 @@ -28,7 +28,7 @@ function RunAsScheduledTask { function RemoveEdgeChromium { [CmdletBinding()] param ( - [String]$AsTask + [Switch]$AsTask ) $baseKey = "HKLM:\SOFTWARE\WOW6432Node\Microsoft" @@ -98,7 +98,7 @@ function RemoveEdgeAppX { function RemoveWebView { [CmdletBinding()] param ( - [String]$AsTask + [Switch]$AsTask ) $webviewUninstallKeyPath = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView" if (Test-Path $webviewUninstallKeyPath) {