From 6c3539edbec6f64681089144a51e3d11d9957ed7 Mon Sep 17 00:00:00 2001 From: MyDrift Date: Tue, 13 Aug 2024 20:49:08 +0200 Subject: [PATCH] Edge removal improvements (#2540) * readd changes - change uninstall function call - remove winget install code - add edge install function call - remove reg keys causing cursed open with contect menu - remove edge policy keys - remove edge keys - remove edgeupdate keys - add install edg logics * add silent installation * error handling * add ... --- config/tweaks.json | 9 +--- .../private/Uninstall-WinUtilEdgeBrowser.ps1 | 43 +++++++++++++++++-- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/config/tweaks.json b/config/tweaks.json index 8702322f..07c17d85 100644 --- a/config/tweaks.json +++ b/config/tweaks.json @@ -2561,15 +2561,10 @@ "panel": "1", "Order": "a029_", "InvokeScript": [ - " - Uninstall-WinUtilEdgeBrowser - " + "Uninstall-WinUtilEdgeBrowser -action \"Uninstall\"" ], "UndoScript": [ - " - Write-Host \"Install Microsoft Edge\" - Start-Process -FilePath winget -ArgumentList \"install --force -e --accept-source-agreements --accept-package-agreements --silent Microsoft.Edge \" -NoNewWindow -Wait - " + "Uninstall-WinUtilEdgeBrowser -action \"Install\"" ], "link": "https://christitustech.github.io/winutil/dev/tweaks/z--Advanced-Tweaks---CAUTION/RemoveEdge" }, diff --git a/functions/private/Uninstall-WinUtilEdgeBrowser.ps1 b/functions/private/Uninstall-WinUtilEdgeBrowser.ps1 index 4d004f39..f090e95f 100644 --- a/functions/private/Uninstall-WinUtilEdgeBrowser.ps1 +++ b/functions/private/Uninstall-WinUtilEdgeBrowser.ps1 @@ -6,6 +6,12 @@ Function Uninstall-WinUtilEdgeBrowser { This will switch up the region to one of the EEA countries temporarily and uninstall the Edge Browser (Chromium). #> + param ( + [Parameter(Mandatory = $true)] + [ValidateSet("install", "uninstall")] + [string]$action + ) + function Uninstall-EdgeClient { param ( [Parameter(Mandatory = $true)] @@ -65,6 +71,16 @@ Function Uninstall-WinUtilEdgeBrowser { [microsoft.win32.registry]::SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdateDev", "AllowUninstall", 1, [Microsoft.Win32.RegistryValueKind]::DWord) | Out-Null Uninstall-EdgeClient -Key '{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}' + + Remove-Item -Path "Computer\\HKEY_CLASSES_ROOT\\MSEdgePDF" -ErrorAction SilentlyContinue | Out-Null + Remove-Item -Path "Computer\\HKEY_CLASSES_ROOT\\MSEdgeHTM" -ErrorAction SilentlyContinue | Out-Null + Remove-Item -Path "Computer\\HKEY_CLASSES_ROOT\\MSEdgeMHT" -ErrorAction SilentlyContinue | Out-Null + + # Remove Edge Polocy reg keys + Remove-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Edge" -Recurse -ErrorAction SilentlyContinue | Out-Null + + # Remove Edge reg keys + Remove-Item -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Edge" -Recurse -ErrorAction SilentlyContinue | Out-Null } function Uninstall-WebView { @@ -93,9 +109,30 @@ Function Uninstall-WinUtilEdgeBrowser { } Start-Process cmd.exe "/c $uninstallCmdLine" -WindowStyle Hidden -Wait + + # Remove EdgeUpdate reg keys + Remove-Item -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate" -Recurse -ErrorAction SilentlyContinue | Out-Null } - Uninstall-Edge - # Uninstall-WebView - WebView is needed for Visual Studio and some MS Store Games like Forza - Uninstall-EdgeUpdate + function Install-Edge { + $tempEdgePath = "$env:TEMP\MicrosoftEdgeSetup.exe" + + try { + write-host "Installing Edge ..." + Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/?linkid=2109047&Channel=Stable&language=en&consent=1" -OutFile $tempEdgePath + Start-Process -FilePath $tempEdgePath -ArgumentList "/silent /install" -Wait + Remove-item $tempEdgePath + write-host "Edge Installed Successfully" + } catch { + write-host "Failed to install Edge" + } + } + + if ($action -eq "Install") { + Install-Edge + } elseif ($action -eq "Uninstall") { + Uninstall-Edge + Uninstall-EdgeUpdate + # Uninstall-WebView - WebView is needed for Visual Studio and some MS Store Games like Forza + } }