Skip to content

Commit

Permalink
Added option to forcefully remove edge (#82)
Browse files Browse the repository at this point in the history
Additionally:
* Added extra check to Get.ps1 to prevent error if user cancels UAC prompt 
* Removed Dolby from appslist (#78)
  • Loading branch information
Raphire authored Jul 2, 2024
1 parent 6614cdf commit 6049800
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 17 deletions.
1 change: 0 additions & 1 deletion Appslist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ COOKINGFEVER
CyberLinkMediaSuiteEssentials
DisneyMagicKingdoms
Disney
Dolby
DrawboardPDF
Duolingo-LearnLanguagesforFree
EclipseManager
Expand Down
7 changes: 6 additions & 1 deletion Get.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ param (
[switch]$RemoveCommApps,
[switch]$RemoveDevApps,
[switch]$RemoveW11Outlook,
[switch]$ForceRemoveEdge,
[switch]$DisableDVR,
[switch]$DisableTelemetry,
[switch]$DisableBingSearches, [switch]$DisableBing,
Expand Down Expand Up @@ -81,7 +82,11 @@ Write-Output "> Running Win11Debloat..."

# Run Win11Debloat script with the provided arguments
$debloatProcess = Start-Process powershell.exe -PassThru -ArgumentList "-executionpolicy bypass -File $env:TEMP\Win11Debloat\Win11Debloat-master\Win11Debloat.ps1 $arguments" -Verb RunAs
$debloatProcess.WaitForExit()

# Wait for the process to finish before continuing
if($debloatProcess -ne $null) {
$debloatProcess.WaitForExit()
}

Write-Output ""
Write-Output "> Cleaning up..."
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ The quick and advanced method support parameters to tailor the behaviour of the
| -RemoveW11Outlook | Remove the new Outlook for Windows app. |
| -RemoveDevApps | Remove developer-related apps such as Remote Desktop, DevHome and Power Automate. |
| -RemoveGamingApps | Remove the Xbox App and Xbox Gamebar. |
| -ForceRemoveEdge | Forcefully remove Microsoft Edge. NOT RECOMMENDED! |
| -DisableDVR | Disable Xbox game/screen recording feature & stop gaming overlay popups. |
| -ClearStart | Remove all pinned apps from start for the current user (Windows 11 update 22H2 or later only) |
| -ClearStartAllUsers | Remove all pinned apps from start for all existing and new users. (Windows 11 update 22H2 or later only) |
Expand Down
125 changes: 110 additions & 15 deletions Win11Debloat.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ param (
[switch]$RemoveCommApps,
[switch]$RemoveDevApps,
[switch]$RemoveW11Outlook,
[switch]$ForceRemoveEdge,
[switch]$DisableDVR,
[switch]$DisableTelemetry,
[switch]$DisableBingSearches, [switch]$DisableBing,
Expand Down Expand Up @@ -44,7 +45,7 @@ param (

# Show error if current powershell environment does not have LanguageMode set to FullLanguage
if ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage") {
Write-Host "Error: Win11Debloat is unable to run on your system. Powershell execution is restricted by security policies" -ForegroundColor Red
Write-Host "Error: Win11Debloat is unable to run on your system, powershell execution is restricted by security policies" -ForegroundColor Red
Write-Output ""
Write-Output "Press enter to exit..."
Read-Host | Out-Null
Expand Down Expand Up @@ -187,18 +188,12 @@ function ShowAppSelectionForm {
if ($appString.length -gt 0) {
if ($onlyInstalledCheckBox.Checked) {
# onlyInstalledCheckBox is checked, check if app is installed before adding it to selectionBox
if ($listOfApps -like ("*$appString*")) {
$installed = "installed"
}
elseif (($appString -eq "Microsoft.Edge") -and ($listOfApps -like "* XPFFTQ037JWMHS *")) {
$installed = "installed"
}
else {
$installed = Get-AppxPackage -Name $app
if (-not ($listOfApps -like ("*$appString*")) -and -not (Get-AppxPackage -Name $app)) {
# App is not installed, continue with next item
continue
}

if ($installed.length -eq 0) {
# App is not installed, continue to next item without adding this app to the selectionBox
if (($appString -eq "Microsoft.Edge") -and -not ($listOfApps -like "* Microsoft.Edge *")) {
# App is not installed, continue with next item
continue
}
}
Expand Down Expand Up @@ -350,7 +345,16 @@ function RemoveApps {
}
else {
# Uninstall app via winget
winget uninstall --accept-source-agreements --disable-interactivity --id $app
Strip-Progress -ScriptBlock { winget uninstall --accept-source-agreements --disable-interactivity --id $app } | Tee-Object -Variable wingetOutput

If (($app -eq "Microsoft.Edge") -and (Select-String -InputObject $wingetOutput -Pattern "93")) {
Write-Host "Error: Unable to uninstall Microsoft Edge via Winget" -ForegroundColor Red
Write-Output ""

if ($( Read-Host -Prompt "Would you like to forcefully uninstall Edge? NOT RECOMMENDED! (y/n)" ) -eq 'y') {
ForceRemoveEdge
}
}
}
}
else {
Expand All @@ -374,6 +378,93 @@ function RemoveApps {
}


function ForceRemoveEdge {
# Based on work from loadstring1 & ave9858
Write-Output ""
Write-Output "> Forcefully uninstalling Microsoft Edge..."

$regView = [Microsoft.Win32.RegistryView]::Registry32
$hklm = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $regView)
$hklm.CreateSubKey('SOFTWARE\Microsoft\EdgeUpdateDev').SetValue('AllowUninstall', '')

# Create stub (Creating this somehow allows uninstalling edge)
$edgeStub = "$env:SystemRoot\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe"
New-Item $edgeStub -ItemType Directory | Out-Null
New-Item "$edgeStub\MicrosoftEdge.exe" | Out-Null

# Remove edge
$uninstallRegKey = $hklm.OpenSubKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge')
if($uninstallRegKey -ne $null) {
Write-Output "Running uninstaller..."
$uninstallString = $uninstallRegKey.GetValue('UninstallString') + ' --force-uninstall'
Start-Process cmd.exe "/c $uninstallString" -WindowStyle Hidden -Wait

Write-Output "Removing leftover files..."

$appdata = $([Environment]::GetFolderPath('ApplicationData'))

$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:PUBLIC\Desktop\Microsoft Edge.lnk",
"$env:USERPROFILE\Desktop\Microsoft Edge.lnk",
"$appdata\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Tombstones\Microsoft Edge.lnk",
"$appdata\Microsoft\Internet Explorer\Quick Launch\Microsoft Edge.lnk",
"$edgeStub"
)

foreach ($path in $edgePaths){
if (Test-Path -Path $path) {
Remove-Item -Path $path -Force -Recurse -ErrorAction SilentlyContinue
Write-Host " Removed $path" -ForegroundColor DarkGray
}
}

Write-Output "Cleaning up registry..."

# Remove ms edge from autostart
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" /v "MicrosoftEdgeAutoLaunch_A9F6DCE4ABADF4F51CF45CD7129E3C6C" /f *>$null
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" /v "Microsoft Edge Update" /f *>$null
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run" /v "MicrosoftEdgeAutoLaunch_A9F6DCE4ABADF4F51CF45CD7129E3C6C" /f *>$null
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run" /v "Microsoft Edge Update" /f *>$null

Write-Output "Microsoft Edge was uninstalled"
}
else {
Write-Output ""
Write-Host "Error: Unable to forcefully uninstall Microsoft Edge, uninstaller could not be found" -ForegroundColor Red
}

Write-Output ""
}


# Execute provided command and strips progress spinners/bars from console output
function Strip-Progress {
param(
[ScriptBlock]$ScriptBlock
)

# Regex pattern to match spinner characters and progress bar patterns
$progressPattern = 'Γû[Æê]|^\s+[-\\|/]\s+$'

# Corrected regex pattern for size formatting, ensuring proper capture groups are utilized
$sizePattern = '(\d+(\.\d{1,2})?)\s+(B|KB|MB|GB|TB|PB) /\s+(\d+(\.\d{1,2})?)\s+(B|KB|MB|GB|TB|PB)'

& $ScriptBlock 2>&1 | ForEach-Object {
if ($_ -is [System.Management.Automation.ErrorRecord]) {
"ERROR: $($_.Exception.Message)"
} else {
$line = $_ -replace $progressPattern, '' -replace $sizePattern, ''
if (-not ([string]::IsNullOrWhiteSpace($line)) -and -not ($line.StartsWith(' '))) {
$line
}
}
}
}


# Import & execute regfile
function RegImport {
param (
Expand Down Expand Up @@ -1036,13 +1127,13 @@ if ((-not $global:Params.Count) -or $RunDefaults -or $RunWin11Defaults -or ($SPP
Write-Output ""
Write-Output "Press enter to remove the selected apps or press CTRL+C to quit..."
Read-Host | Out-Null
PrintHeader "App Removal"
}
}
else {
Write-Host "Selection was cancelled, no apps have been removed!" -ForegroundColor Red
Write-Output ""
}

Write-Output ""
}

# Load custom options selection from the "SavedSettings" file
Expand Down Expand Up @@ -1179,6 +1270,10 @@ else {

continue
}
"ForceRemoveEdge" {
ForceRemoveEdge
continue
}
'DisableDVR' {
RegImport "> Disabling Xbox game/screen recording..." "Disable_DVR.reg"
continue
Expand Down

0 comments on commit 6049800

Please sign in to comment.