Skip to content

Commit

Permalink
Merge branch 'dev' into ame-customisation
Browse files Browse the repository at this point in the history
  • Loading branch information
he3als committed Jul 12, 2023
2 parents 4667a36 + a4e856e commit c574f87
Showing 1 changed file with 66 additions and 10 deletions.
76 changes: 66 additions & 10 deletions src/Executables/Atlas/1. Software/Remove Edge.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[CmdletBinding()]
param (
[Switch]$RemoveAllEdge
[Switch]$Setup
)

$ProgressPreference = "SilentlyContinue"
Expand All @@ -10,8 +10,43 @@ 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 (
[Switch]$AsTask
)
$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}"
Expand All @@ -31,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
Expand All @@ -50,17 +88,24 @@ 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
Remove-Item -Path "HKLM:$appxStore\EndOfLife\$SID\Microsoft.MicrosoftEdge_8wekyb3d8bbwe" -Force | Out-Null
}

function RemoveWebView {
[CmdletBinding()]
param (
[Switch]$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
}
}
}

Expand All @@ -75,21 +120,32 @@ 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 -AsTask
Write-Warning "Uninstalling Edge WebView..."
RemoveWebView -AsTask
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)) {
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)) {
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"}
Expand Down

0 comments on commit c574f87

Please sign in to comment.