2026-07-19 22:06:07 +02:00
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Forcefully uninstalls Microsoft Edge and removes its leftover shortcuts and autostart entries.
|
|
|
|
|
#>
|
|
|
|
|
function Invoke-ForceRemoveEdge {
|
2026-08-12 21:10:47 +02:00
|
|
|
if ($script:Params.ContainsKey("WhatIf")) {
|
|
|
|
|
Write-Host "[WhatIf] Forcefully uninstall Microsoft Edge" -ForegroundColor Cyan
|
2026-08-15 17:08:00 +02:00
|
|
|
return $true
|
2026-08-12 21:10:47 +02:00
|
|
|
}
|
|
|
|
|
|
2026-08-15 17:08:00 +02:00
|
|
|
try {
|
|
|
|
|
Write-Host "> Forcefully uninstalling Microsoft Edge..."
|
2026-03-07 20:28:48 +01:00
|
|
|
|
2026-08-15 17:08:00 +02:00
|
|
|
$regView = [Microsoft.Win32.RegistryView]::Registry32
|
|
|
|
|
$hklm = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $regView)
|
|
|
|
|
$hklm.CreateSubKey('SOFTWARE\Microsoft\EdgeUpdateDev').SetValue('AllowUninstall', '')
|
2026-03-07 20:28:48 +01:00
|
|
|
|
2026-08-15 17:08:00 +02:00
|
|
|
# Create stub (This somehow allows uninstalling Edge)
|
|
|
|
|
$edgeStub = "$env:SystemRoot\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe"
|
|
|
|
|
New-Item $edgeStub -ItemType Directory -Force -ErrorAction Stop | Out-Null
|
|
|
|
|
New-Item "$edgeStub\MicrosoftEdge.exe" -ItemType File -Force -ErrorAction Stop | Out-Null
|
2026-03-07 20:28:48 +01:00
|
|
|
|
|
|
|
|
# Remove edge
|
2026-08-15 17:08:00 +02:00
|
|
|
$uninstallRegKey = $hklm.OpenSubKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge')
|
|
|
|
|
if ($null -eq $uninstallRegKey) {
|
|
|
|
|
Write-Host "Unable to forcefully uninstall Microsoft Edge, uninstaller could not be found" -ForegroundColor Red
|
|
|
|
|
return $false
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-07 20:28:48 +01:00
|
|
|
Write-Host "Running uninstaller..."
|
|
|
|
|
$uninstallString = $uninstallRegKey.GetValue('UninstallString') + ' --force-uninstall'
|
2026-08-15 17:08:00 +02:00
|
|
|
$exitCode = Invoke-NonBlocking -ScriptBlock {
|
2026-03-07 20:28:48 +01:00
|
|
|
param($cmd)
|
2026-08-15 17:08:00 +02:00
|
|
|
$process = Start-Process cmd.exe "/c $cmd" -WindowStyle Hidden -Wait -PassThru
|
|
|
|
|
return $process.ExitCode
|
2026-03-07 20:28:48 +01:00
|
|
|
} -ArgumentList $uninstallString
|
2026-08-15 17:08:00 +02:00
|
|
|
if ($exitCode -ne 0) {
|
|
|
|
|
Write-Warning "Microsoft Edge uninstaller failed with exit code $exitCode."
|
|
|
|
|
return $false
|
|
|
|
|
}
|
2026-03-07 20:28:48 +01:00
|
|
|
|
|
|
|
|
Write-Host "Removing leftover files..."
|
2026-08-15 17:08:00 +02:00
|
|
|
$cleanupSucceeded = $true
|
2026-03-07 20:28:48 +01:00
|
|
|
|
|
|
|
|
$edgePaths = @(
|
|
|
|
|
"$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk",
|
|
|
|
|
"$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\Microsoft Edge.lnk",
|
|
|
|
|
"$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Edge.lnk",
|
|
|
|
|
"$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Tombstones\Microsoft Edge.lnk",
|
|
|
|
|
"$env:PUBLIC\Desktop\Microsoft Edge.lnk",
|
|
|
|
|
"$env:USERPROFILE\Desktop\Microsoft Edge.lnk",
|
|
|
|
|
"$edgeStub"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
foreach ($path in $edgePaths) {
|
|
|
|
|
if (Test-Path -Path $path) {
|
2026-08-15 17:08:00 +02:00
|
|
|
try {
|
|
|
|
|
Remove-Item -Path $path -Force -Recurse -ErrorAction Stop
|
|
|
|
|
Write-Host " Removed $path" -ForegroundColor DarkGray
|
|
|
|
|
}
|
|
|
|
|
catch {
|
|
|
|
|
Write-Warning "Failed to remove Edge leftover '$path': $($_.Exception.Message)"
|
|
|
|
|
$cleanupSucceeded = $false
|
|
|
|
|
}
|
2026-03-07 20:28:48 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Write-Host "Cleaning up registry..."
|
2026-08-15 17:08:00 +02:00
|
|
|
$registryCleanupSucceeded = $true
|
2026-03-07 20:28:48 +01:00
|
|
|
|
2026-08-15 17:08:00 +02:00
|
|
|
# Remove MS Edge from autostart. Missing values are already-clean state,
|
|
|
|
|
# while failures to inspect or remove an existing value are reported.
|
|
|
|
|
$autostartValues = @(
|
|
|
|
|
@{ Path = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Run'; Name = 'MicrosoftEdgeAutoLaunch_A9F6DCE4ABADF4F51CF45CD7129E3C6C' },
|
|
|
|
|
@{ Path = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Run'; Name = 'Microsoft Edge Update' },
|
|
|
|
|
@{ Path = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run'; Name = 'MicrosoftEdgeAutoLaunch_A9F6DCE4ABADF4F51CF45CD7129E3C6C' },
|
|
|
|
|
@{ Path = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run'; Name = 'Microsoft Edge Update' }
|
|
|
|
|
)
|
|
|
|
|
foreach ($autostartValue in $autostartValues) {
|
|
|
|
|
if (-not (Remove-EdgeAutostartValue -Path $autostartValue.Path -Name $autostartValue.Name)) {
|
|
|
|
|
$registryCleanupSucceeded = $false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (-not $cleanupSucceeded -or -not $registryCleanupSucceeded) {
|
|
|
|
|
Write-Warning "Microsoft Edge was uninstalled, but some leftover files or autostart entries could not be removed."
|
|
|
|
|
return $false
|
|
|
|
|
}
|
2026-03-07 20:28:48 +01:00
|
|
|
|
|
|
|
|
Write-Host "Microsoft Edge was uninstalled"
|
2026-08-15 17:08:00 +02:00
|
|
|
return $true
|
2026-03-07 20:28:48 +01:00
|
|
|
}
|
2026-08-15 17:08:00 +02:00
|
|
|
catch {
|
|
|
|
|
Write-Warning "Failed to forcefully uninstall Microsoft Edge: $($_.Exception.Message)"
|
|
|
|
|
return $false
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
if ($uninstallRegKey) { $uninstallRegKey.Dispose() }
|
|
|
|
|
if ($hklm) { $hklm.Dispose() }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Remove-EdgeAutostartValue {
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory)]
|
|
|
|
|
[string]$Path,
|
|
|
|
|
[Parameter(Mandatory)]
|
|
|
|
|
[string]$Name
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$properties = Get-ItemProperty -Path $Path -ErrorAction Stop
|
|
|
|
|
}
|
|
|
|
|
catch [System.Management.Automation.ItemNotFoundException] {
|
|
|
|
|
return $true
|
|
|
|
|
}
|
|
|
|
|
catch {
|
|
|
|
|
Write-Warning "Failed to inspect Edge autostart entry '$Path\$Name': $($_.Exception.Message)"
|
|
|
|
|
return $false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (-not $properties.PSObject.Properties[$Name]) {
|
|
|
|
|
return $true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Remove-ItemProperty -Path $Path -Name $Name -ErrorAction Stop
|
|
|
|
|
return $true
|
|
|
|
|
}
|
|
|
|
|
catch {
|
|
|
|
|
Write-Warning "Failed to remove Edge autostart entry '$Path\$Name': $($_.Exception.Message)"
|
|
|
|
|
return $false
|
2026-03-07 20:28:48 +01:00
|
|
|
}
|
2026-07-19 22:06:07 +02:00
|
|
|
}
|