Skip to content

Commit f921557

Browse files
committed
feat: more commits from Atlas
1 parent 56539ed commit f921557

File tree

1 file changed

+66
-10
lines changed

1 file changed

+66
-10
lines changed

Remove Edge.ps1

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[CmdletBinding()]
22
param (
3-
[Switch]$RemoveAllEdge
3+
[Switch]$Setup
44
)
55

66
$ProgressPreference = "SilentlyContinue"
@@ -10,8 +10,43 @@ function PauseNul ($message = "Press any key to continue... ") {
1010
$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') | Out-Null
1111
}
1212

13+
# removing Edge Chromium & WebView is meant to be compatible with TrustedInstaller for AME Wizard
14+
# running the uninstaller as TrustedInstaller causes shortcuts and other things not to be removed properly
15+
function RunAsScheduledTask {
16+
[CmdletBinding()]
17+
param (
18+
[String]$Command
19+
)
20+
$user = (Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -ExpandProperty UserName) -replace ".*\\"
21+
$action = New-ScheduledTaskAction -Execute "$env:windir\System32\cmd.exe" -Argument "/c $Command"
22+
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
23+
$title = "RemoveEdge $(Get-Random -minimum 9999999999)"
24+
Register-ScheduledTask -TaskName $title -Action $action -Settings $settings -User $user -RunLevel Highest -Force | Start-ScheduledTask | Out-Null
25+
Unregister-ScheduledTask -TaskName $title -Confirm:$false | Out-Null
26+
}
27+
1328
function RemoveEdgeChromium {
29+
[CmdletBinding()]
30+
param (
31+
[Switch]$AsTask
32+
)
1433
$baseKey = "HKLM:\SOFTWARE\WOW6432Node\Microsoft"
34+
35+
# kill Edge
36+
$ErrorActionPreference = 'SilentlyContinue'
37+
38+
Get-Process -Name MicrosoftEdgeUpdate | Stop-Process -Force
39+
Get-Process -Name msedge | Stop-Process -Force
40+
41+
$services = @(
42+
'edgeupdate',
43+
'edgeupdatem',
44+
'MicrosoftEdgeElevationService'
45+
)
46+
47+
foreach ($service in $services) {Stop-Service -Name $service -Force}
48+
49+
$ErrorActionPreference = 'Continue'
1550

1651
# check if 'experiment_control_labels' value exists and delete it if found
1752
$keyPath = Join-Path -Path $baseKey -ChildPath "EdgeUpdate\ClientState\{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}"
@@ -31,8 +66,11 @@ function RemoveEdgeChromium {
3166
# uninstall Edge
3267
$uninstallKeyPath = Join-Path -Path $baseKey -ChildPath "Windows\CurrentVersion\Uninstall\Microsoft Edge"
3368
if (Test-Path $uninstallKeyPath) {
34-
$uninstallString = (Get-ItemProperty -Path $uninstallKeyPath).UninstallString
35-
Start-Process cmd.exe "/c $uninstallString --force-uninstall" -WindowStyle Hidden
69+
$uninstallString = (Get-ItemProperty -Path $uninstallKeyPath).UninstallString + " --force-uninstall"
70+
# create a scheduled task as current user so that it works properly with TI perms
71+
if ($AsTask) {RunAsScheduledTask -Command $uninstallString} else {
72+
Start-Process cmd.exe "/c $uninstallString" -WindowStyle Hidden
73+
}
3674
}
3775

3876
# remove user data
@@ -50,17 +88,24 @@ function RemoveEdgeAppX {
5088
if (Test-Path "$pattern") { reg delete "HKLM$appxStore\InboxApplications\$edgeAppXKey" /f | Out-Null }
5189

5290
# make the Edge AppX able to uninstall and uninstall
91+
$user = (Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -ExpandProperty UserName) -replace ".*\\"
5392
$SID = (New-Object System.Security.Principal.NTAccount($env:USERNAME)).Translate([Security.Principal.SecurityIdentifier]).Value
5493
New-Item -Path "HKLM:$appxStore\EndOfLife\$SID\Microsoft.MicrosoftEdge_8wekyb3d8bbwe" -Force | Out-Null
5594
Get-AppxPackage -Name Microsoft.MicrosoftEdge | Remove-AppxPackage | Out-Null
5695
Remove-Item -Path "HKLM:$appxStore\EndOfLife\$SID\Microsoft.MicrosoftEdge_8wekyb3d8bbwe" -Force | Out-Null
5796
}
5897

5998
function RemoveWebView {
99+
[CmdletBinding()]
100+
param (
101+
[Switch]$AsTask
102+
)
60103
$webviewUninstallKeyPath = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView"
61104
if (Test-Path $webviewUninstallKeyPath) {
62-
$webviewUninstallString = (Get-ItemProperty -Path $webviewUninstallKeyPath).UninstallString
63-
Start-Process cmd.exe "/c $webviewUninstallString --force-uninstall" -WindowStyle Hidden
105+
$webviewUninstallString = (Get-ItemProperty -Path $webviewUninstallKeyPath).UninstallString + " --force-uninstall"
106+
if ($AsTask) {RunAsScheduledTask -Command $webviewUninstallString} else {
107+
Start-Process cmd.exe "/c $uninstallString" -WindowStyle Hidden
108+
}
64109
}
65110
}
66111

@@ -75,21 +120,32 @@ function UninstallAll {
75120
}
76121
}
77122

78-
if ($RemoveAllEdge) {
79-
$removeWebView = $true
123+
# AppX is not removed as it's handled by AME Wizard
124+
if ($Setup) {
80125
$removeData = $true
81-
UninstallAll
126+
Write-Warning "Uninstalling Edge Chromium..."
127+
RemoveEdgeChromium -AsTask
128+
Write-Warning "Uninstalling Edge WebView..."
129+
RemoveWebView -AsTask
130+
Write-Warning "The AppX Edge needs to be removed by AME Wizard..."
131+
exit
82132
}
83133

84134
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) {
85135
Start-Process PowerShell "-NoProfile -ExecutionPolicy Unrestricted -File `"$PSCommandPath`"" -Verb RunAs; exit
86136
}
87137

138+
if ($(whoami /user | Select-String "S-1-5-18") -ne $null) {
139+
Write-Host "This script can't be ran as TrustedInstaller or SYSTEM."
140+
Write-Host "Please relaunch this script under a regular admin account.`n"
141+
PauseNul "Press any key to exit... "
142+
exit 1
143+
}
144+
88145
$removeWebView = $false
89146
$removeData = $true
90147
while (!($continue)) {
91-
cls
92-
Write-Host "This script will remove Microsoft Edge, as once you install it, you can't normally uninstall it.
148+
cls; Write-Host "This script will remove Microsoft Edge, as once you install it, you can't normally uninstall it.
93149
Major credit to ave9858: https://gist.github.com/ave9858/c3451d9f452389ac7607c99d45edecc6`n" -ForegroundColor Yellow
94150

95151
if ($removeWebView) {$colourWeb = "Green"; $textWeb = "Selected"} else {$colourWeb = "Red"; $textWeb = "Unselected"}

0 commit comments

Comments
 (0)