Skip to content

Commit 665ebcc

Browse files
committed
fix(v1.0.1): formatting & another TI issue
1 parent 96232f9 commit 665ebcc

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

RemoveEdge.ps1

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ param (
44
)
55

66
$ProgressPreference = "SilentlyContinue"
7+
$user = (Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -ExpandProperty UserName) -replace ".*\\"
8+
$SID = (New-Object System.Security.Principal.NTAccount($user)).Translate([Security.Principal.SecurityIdentifier]).Value
79

810
function PauseNul ($message = "Press any key to continue... ") {
911
Write-Host $message -NoNewLine
@@ -17,7 +19,6 @@ function RunAsScheduledTask {
1719
param (
1820
[String]$Command
1921
)
20-
$user = (Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -ExpandProperty UserName) -replace ".*\\"
2122
$action = New-ScheduledTaskAction -Execute "$env:windir\System32\cmd.exe" -Argument "/c $Command"
2223
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
2324
$title = "RemoveEdge $(Get-Random -minimum 9999999999)"
@@ -75,7 +76,7 @@ function RemoveEdgeChromium {
7576

7677
# remove user data
7778
if ($removeData) {
78-
$path = "$env:LOCALAPPDATA\Microsoft\Edge"
79+
$path = "$env:SystemDrive\Users\$user\AppData\Local\Microsoft\Edge"
7980
if (Test-Path $path) {Remove-Item $path -Force -Recurse}
8081
}
8182
}
@@ -88,8 +89,6 @@ function RemoveEdgeAppX {
8889
if (Test-Path "$pattern") { reg delete "HKLM$appxStore\InboxApplications\$edgeAppXKey" /f | Out-Null }
8990

9091
# make the Edge AppX able to uninstall and uninstall
91-
$user = (Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -ExpandProperty UserName) -replace ".*\\"
92-
$SID = (New-Object System.Security.Principal.NTAccount($user)).Translate([Security.Principal.SecurityIdentifier]).Value
9392
New-Item -Path "HKLM:$appxStore\EndOfLife\$SID\Microsoft.MicrosoftEdge_8wekyb3d8bbwe" -Force | Out-Null
9493
Get-AppxPackage -Name Microsoft.MicrosoftEdge | Remove-AppxPackage | Out-Null
9594
Remove-Item -Path "HKLM:$appxStore\EndOfLife\$SID\Microsoft.MicrosoftEdge_8wekyb3d8bbwe" -Force | Out-Null
@@ -111,35 +110,34 @@ function RemoveWebView {
111110

112111
function UninstallAll {
113112
Write-Warning "Uninstalling Edge Chromium..."
114-
RemoveEdgeChromium
115-
Write-Warning "Uninstalling AppX Edge..."
116-
RemoveEdgeAppx
113+
if ($Setup) {RemoveEdgeChromium -AsTask} else {RemoveEdgeChromium}
114+
if (!($Setup)) {
115+
Write-Warning "Uninstalling AppX Edge..."
116+
RemoveEdgeAppx
117+
} else {Write-Warning "AppX Edge needs to be removed by AME Wizard..."}
117118
if ($removeWebView) {
118119
Write-Warning "Uninstalling Edge WebView..."
119-
RemoveWebView
120+
if ($Setup) {RemoveWebView -AsTask} else {RemoveWebView}
120121
}
121122
}
122123

123124
# AppX is not removed as it's handled by AME Wizard
124125
if ($Setup) {
125126
$removeData = $true
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..."
127+
$removeWebView = $true
128+
UninstallAll
131129
exit
132130
}
133131

134-
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) {
135-
Start-Process PowerShell "-NoProfile -ExecutionPolicy Unrestricted -File `"$PSCommandPath`"" -Verb RunAs; exit
136-
}
137-
138132
if ($null -ne $(whoami /user | Select-String "S-1-5-18")) {
139133
Write-Host "This script can't be ran as TrustedInstaller or SYSTEM."
140134
Write-Host "Please relaunch this script under a regular admin account.`n"
141135
PauseNul "Press any key to exit... "
142136
exit 1
137+
} else {
138+
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) {
139+
Start-Process PowerShell "-NoProfile -ExecutionPolicy Unrestricted -File `"$PSCommandPath`"" -Verb RunAs; exit
140+
}
143141
}
144142

145143
$removeWebView = $false
@@ -156,11 +154,11 @@ Major credit to ave9858: https://gist.github.com/ave9858/c3451d9f452389ac7607c99
156154
Write-Host "[2] Remove Edge User Data ($textData)`n" -ForegroundColor $colourData
157155
Write-Host "Press enter to continue or use numbers to select options... " -NoNewLine
158156

159-
$input = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
157+
$userInput = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
160158

161159
write-host "$input.VirtualKeyCode"
162160

163-
switch ($input.VirtualKeyCode) {
161+
switch ($userInput.VirtualKeyCode) {
164162
49 { # num 1
165163
$removeWebView = !$removeWebView
166164
}
@@ -173,7 +171,8 @@ Major credit to ave9858: https://gist.github.com/ave9858/c3451d9f452389ac7607c99
173171
}
174172
}
175173

176-
Clear-Host; UninstallAll
174+
Clear-Host
175+
UninstallAll
177176

178177
Write-Host "`nCompleted." -ForegroundColor Green
179178
PauseNul "Press any key to exit... "

0 commit comments

Comments
 (0)