Skip to content

Commit

Permalink
feat(edge): make compatible with TI (non-AppX)
Browse files Browse the repository at this point in the history
  • Loading branch information
he3als committed Jul 11, 2023
1 parent 4a7fc55 commit 4582378
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions src/Executables/Atlas/1. Software/Remove Edge.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -66,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 (
[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
}
}
}

Expand All @@ -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
}
Expand All @@ -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)) {
Expand Down

0 comments on commit 4582378

Please sign in to comment.