@echo off

set EDGEROOT="C:\Program Files (x86)\Microsoft\Edge"
set EDGEUPDATE="C:\Program Files (x86)\Microsoft\EdgeUpdate"

echo ####### %0 #######

rem is it installed?
reg query "HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\{9459C573-B17A-45AE-9F64-1857B5D58CEE}" /v StubPath 1>nul 2>&1

if %ERRORLEVEL% NEQ 0 (
  echo EDGE browser is NOT installed!
  echo ####### %0 #######
  exit /b
)

rem get path for edge setup ...
FOR /F "skip=2 tokens=2* " %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\{9459C573-B17A-45AE-9F64-1857B5D58CEE}" /v StubPath') do set EDGESETUP=%%b

rem delete everthing before the word "Application" ...
call set EDGESETUP=%%EDGESETUP:*Application\=%%

rem delete everything after the \ ...
set "EDGESETUP=%EDGESETUP:\=" & rem."%"

echo found EDGE version [ %EDGESETUP% ] ...
set INSTALLER=Application\%EDGESETUP%\Installer

echo UNINSTALLING edge browser ...
%EDGEROOT%\%INSTALLER%\setup.exe --uninstall --system-level --verbose-logging --force-uninstall 2>nul

echo sleeping 5 seconds ...
ping 127.0.0.1 -n 5 >nul 2>&1

echo CLEANUP ...
rd /S /Q %EDGEROOT% 2>nul
rd /S /Q %EDGEUPDATE% 2>nul
del /F /Q "%PUBLIC%\Desktop\Microsoft Edge.lnk" 2>nul
del /F /Q "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk" 2>nul
del /F /Q "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk" 2>nul
del /F /Q "%USERPROFILE%\Desktop\Microsoft Edge.lnk" 2>nul
rd /S /Q "%PROGRAMDATA%\Microsoft\EdgeUpdate" 2>nul

echo REMOVING edge browser update task ...
powershell -Command "Get-ScheduledTask | Where-Object {$_.Taskname -match 'EdgeUpdate'} | Unregister-ScheduledTask -Confirm:$false"

echo BLOCKING further edge updates ...
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\EdgeUpdate" ^
  /v "DoNotUpdateToEdgeWithChromium" /d 1 /t REG_DWORD /f

echo REMOVING active setup registry key ...
reg delete "HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\{9459C573-B17A-45AE-9F64-1857B5D58CEE}" /f > NUL 2>&1

echo REMOVING edge update from apps list ...
reg delete "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge Update" /f 1>nul 2>&1

echo REMOVING EDGE from apps list ...
reg delete "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge" /f 1>nul 2>&1

echo ####### %0 #######

