Skip to content

Commit

Permalink
feat: rewrite Edge script partially & remove WebView
Browse files Browse the repository at this point in the history
  • Loading branch information
he3als committed Jul 10, 2023
1 parent 5e1b69b commit 7e756b4
Showing 1 changed file with 79 additions and 25 deletions.
104 changes: 79 additions & 25 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]$RemoveEdge
[Switch]$RemoveAllEdgeSilent
)

$ProgressPreference = "SilentlyContinue"
Expand All @@ -11,41 +11,67 @@ function PauseNul ($message = "Press any key to continue... ") {
}

function RemoveEdgeChromium {
$regView = [Microsoft.Win32.RegistryView]::Registry32
$microsoft = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $regView).
OpenSubKey('SOFTWARE\Microsoft', $true)

$edgeClient = $microsoft.OpenSubKey('EdgeUpdate\ClientState\{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}', $true)
if ($null -ne $edgeClient.GetValue('experiment_control_labels')) {
$edgeClient.DeleteValue('experiment_control_labels')
$baseKey = "HKLM:\SOFTWARE\WOW6432Node\Microsoft"

# 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}"
$valueName = "experiment_control_labels"
if (Test-Path $keyPath) {
$valueExists = Get-ItemProperty -Path $keyPath -Name $valueName -ErrorAction SilentlyContinue
if ($valueExists -ne $null) {
Remove-ItemProperty -Path $keyPath -Name $valueName -Force | Out-Null
}
}

$microsoft.CreateSubKey('EdgeUpdateDev').SetValue('AllowUninstall', '')
# allow Edge uninstall
$devKeyPath = Join-Path -Path $baseKey -ChildPath "EdgeUpdateDev"
if (-not (Test-Path $devKeyPath)) { New-Item -Path $devKeyPath -ItemType "Key" -Force | Out-Null }
Set-ItemProperty -Path $devKeyPath -Name "AllowUninstall" -Value "" -Type String -Force | Out-Null

$uninstallRegKey = $microsoft.OpenSubKey('Windows\CurrentVersion\Uninstall\Microsoft Edge')
$uninstallString = $uninstallRegKey.GetValue('UninstallString') + ' --force-uninstall'
Start-Process cmd.exe "/c $uninstallString" -WindowStyle Hidden
# 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
}
}

function RemoveEdgeAppX {
# remove from Registry
$appxStore = '\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore'
$pattern = "HKLM:$appxStore\InboxApplications\Microsoft.MicrosoftEdge_*_neutral__8wekyb3d8bbwe"
$key = (Get-Item -Path $pattern).PSChildName
reg delete "HKLM$appxStore\InboxApplications\$key" /f | Out-Null
$edgeAppXKey = (Get-Item -Path $pattern).PSChildName
if (Test-Path "$pattern") { reg delete "HKLM$appxStore\InboxApplications\$edgeAppXKey" /f | Out-Null }

# make the Edge AppX able to uninstall and uninstall
$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
}

if ($RemoveEdge) {
function RemoveWebView {
$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
}
}

function UninstallAll {
Write-Warning "Uninstalling Edge Chromium..."
RemoveEdgeChromium
Write-Warning "Uninstalling AppX Edge..."
RemoveEdgeAppx
exit
if ($removeWebView) {
Write-Warning "Uninstalling Edge WebView..."
RemoveWebView
}
}

if ($RemoveAllEdgeSilent) {
$removeWebView = $true
UninstallAll
}

if (!(Test-Path "C:\Program Files (x86)\Microsoft\Edge")) {
Expand All @@ -58,13 +84,41 @@ if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdent
Start-Process PowerShell "-NoProfile -ExecutionPolicy Unrestricted -File `"$PSCommandPath`"" -Verb RunAs; exit
}

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"
PauseNul; cls
$removeWebView = $false
while (!($continue)) {
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) {
$colour = "Green"
$text = "Selected"
} else {
$colour = "Red"
$text = "Unselected"
}

Write-Host "Options:"
Write-Host "[1] Remove Edge WebView ($text)`n" -ForegroundColor $colour
Write-Host "Press enter to continue or use numbers to select options... " -NoNewLine

$input = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')

write-host "$input.VirtualKeyCode"

switch ($input.VirtualKeyCode) {
49 { # num 1
$removeWebView = !$removeWebView
}
13 { # enter
$continue = $true
}
}
}

RemoveEdgeChromium
RemoveEdgeAppx
cls
UninstallAll

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

0 comments on commit 7e756b4

Please sign in to comment.