RemoveEdge.bat 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. @(set "0=%~f0"^)#) & powershell -nop -c iex([io.file]::ReadAllText($env:0)) & exit /b
  2. #:: just copy-paste into powershell - it's a standalone hybrid script
  3. sp 'HKCU:\Volatile Environment' 'Edge_Removal' @'
  4. $also_remove_webview = 1
  5. ## why also remove webview? because it is 2 copies of edge, not a slimmed down CEF, and is driving bloated web apps
  6. $also_remove_widgets = 1
  7. ## why also remove widgets? because it is a webview glorified ad portal on msn and bing news cathering to stupid people
  8. $also_remove_xsocial = 1
  9. ## why also remove xsocial? because it starts webview setup every boot - xbox gamebar will still work without the social crap
  10. $host.ui.RawUI.WindowTitle = 'Edge Removal - AveYo, 2023.09.14'
  11. write-host "Run the script again whenever you need to reinstall and update edge or webview..`n"
  12. $remove_appx = @("MicrosoftEdge"); $remove_win32 = @("Microsoft Edge","Microsoft Edge Update"); $skip = @() # @("DevTools")
  13. if ($also_remove_webview -eq 1) {$remove_appx += "Win32WebViewHost"; $remove_win32 += "Microsoft EdgeWebView"}
  14. if ($also_remove_widgets -eq 1) {$remove_appx += "WebExperience"}
  15. if ($also_remove_xsocial -eq 1) {$remove_appx += "GamingServices"}
  16. $global:WEBV = $also_remove_webview -eq 1
  17. $global:IS64 = [Environment]::Is64BitOperatingSystem
  18. $global:IFEO = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options'
  19. $global:EDGE_UID = '{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}'
  20. $global:WEBV_UID = '{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}'
  21. $global:UPDT_UID = '{F3C4FE00-EFD5-403B-9569-398A20F1BA4A}'
  22. $global:PROGRAMS = ($env:ProgramFiles, ${env:ProgramFiles(x86)})[$IS64]
  23. $global:SOFTWARE = ('SOFTWARE', 'SOFTWARE\WOW6432Node')[$IS64]
  24. $global:ALLHIVES = 'HKCU:\SOFTWARE','HKLM:\SOFTWARE','HKCU:\SOFTWARE\Policies','HKLM:\SOFTWARE\Policies'
  25. if ($IS64) { $global:ALLHIVES += "HKCU:\$SOFTWARE","HKLM:\$SOFTWARE","HKCU:\$SOFTWARE\Policies","HKLM:\$SOFTWARE\Policies"}
  26. ## -------------------------------------------------------------------------------------------------------------------------------
  27. ## 1 bonus! enter into powershell console: firefox / edge / webview to install a browser / reinstall edge / webview after removal
  28. function global:firefox { $url = 'https://download.mozilla.org/?product=firefox-stub'
  29. $setup = "$((new-object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path)\Firefox Installer.exe"
  30. write-host $url; Invoke-WebRequest $url -OutFile $setup; start $setup
  31. }
  32. function global:edge { $url = 'https://go.microsoft.com/fwlink/?linkid=2108834&Channel=Stable&language=en'
  33. $setup = "$((new-object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path)\MicrosoftEdgeSetup.exe"
  34. write-host $url; Invoke-WebRequest $url -OutFile $setup; PREPARE_EDGE; start $setup
  35. }
  36. function global:webview { $url = 'https://go.microsoft.com/fwlink/p/?LinkId=2124703'
  37. $setup = "$((new-object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path)\MicrosoftEdgeWebview2Setup.exe"
  38. write-host $url; Invoke-WebRequest $url -OutFile $setup; PREPARE_WEBVIEW; start $setup
  39. }
  40. function global:xsocial { $url = 'https://dlassets-ssl.xboxlive.com/public/content/XboxInstaller/XboxInstaller.exe'
  41. $setup = "$((new-object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path)\XboxInstaller.exe"
  42. write-host $url; Invoke-WebRequest $url -OutFile $setup; PREPARE_WEBVIEW; start $setup
  43. }
  44. ## helper for set-itemproperty remove-itemproperty new-item remove-item with auto test-path
  45. function global:sp_test_path { if (test-path $args[0]) {Microsoft.PowerShell.Management\Set-ItemProperty @args} else {
  46. Microsoft.PowerShell.Management\New-Item $args[0] -force -ea 0 >''; Microsoft.PowerShell.Management\Set-ItemProperty @args} }
  47. function global:rp_test_path { if (test-path $args[0]) {Microsoft.PowerShell.Management\Remove-ItemProperty @args} }
  48. function global:ni_test_path { if (-not (test-path $args[0])) {Microsoft.PowerShell.Management\New-Item @args} }
  49. function global:ri_test_path { if (test-path $args[0]) {Microsoft.PowerShell.Management\Remove-Item @args} }
  50. foreach ($f in 'sp','rp','ni','ri') {set-alias -Name $f -Value "${f}_test_path" -Scope Local -Option AllScope -force -ea 0}
  51. ## helper for edgeupdate reinstall
  52. function global:PREPARE_UPDT($cdp='msedgeupdate', $uid=$UPDT_UID) {
  53. foreach ($f in 'sp','rp','ni','ri') {set-alias -Name $f -Value "${f}_test_path" -Scope Local -Option AllScope -force -ea 0}
  54. foreach ($sw in $ALLHIVES) {
  55. rp "$sw\Microsoft\EdgeUpdate" 'DoNotUpdateToEdgeWithChromium' -force -ea 0
  56. rp "$sw\Microsoft\EdgeUpdate" 'UpdaterExperimentationAndConfigurationServiceControl' -force -ea 0
  57. rp "$sw\Microsoft\EdgeUpdate" "InstallDefault" -force -ea 0
  58. rp "$sw\Microsoft\EdgeUpdate" "Install${uid}" -force -ea 0
  59. rp "$sw\Microsoft\EdgeUpdate" "EdgePreview${uid}" -force -ea 0
  60. rp "$sw\Microsoft\EdgeUpdate" "Update${uid}" -force -ea 0
  61. rp "$sw\Microsoft\EdgeUpdate\ClientState\*" 'experiment_control_labels' -force -ea 0
  62. ri "$sw\Microsoft\EdgeUpdate\Clients\${uid}\Commands" -recurse -force -ea 0
  63. rp "$sw\Microsoft\EdgeUpdateDev\CdpNames" "$cdp-*" -force -ea 0
  64. sp "$sw\Microsoft\EdgeUpdateDev" 'CanContinueWithMissingUpdate' 1 -type Dword -force
  65. sp "$sw\Microsoft\EdgeUpdateDev" 'AllowUninstall' 1 -type Dword -force
  66. }
  67. }
  68. ## helper for edge reinstall - remove bundled OpenWebSearch redirector and edgeupdate policies
  69. function global:PREPARE_EDGE {
  70. foreach ($f in 'sp','rp','ni','ri') {set-alias -Name $f -Value "${f}_test_path" -Scope Local -Option AllScope -force -ea 0}
  71. PREPARE_UPDT 'msedge' $EDGE_UID; PREPARE_UPDT 'msedgeupdate' $UPDT_UID
  72. $MSEDGE = "$PROGRAMS\Microsoft\Edge\Application\msedge.exe"
  73. ri "$IFEO\msedge.exe" -recurse -force; ri "$IFEO\ie_to_edge_stub.exe" -recurse -force
  74. ri 'Registry::HKEY_Users\S-1-5-21*\Software\Classes\microsoft-edge' -recurse -force
  75. sp 'HKLM:\SOFTWARE\Classes\microsoft-edge\shell\open\command' '(Default)' "`"$MSEDGE`" --single-argument %%1" -force
  76. ri 'Registry::HKEY_Users\S-1-5-21*\Software\Classes\MSEdgeHTM' -recurse -force
  77. sp 'HKLM:\SOFTWARE\Classes\MSEdgeHTM\shell\open\command' '(Default)' "`"$MSEDGE`" --single-argument %%1" -force
  78. }
  79. ## helper for webview reinstall - restore webexperience (widgets) if available
  80. function global:PREPARE_WEBVIEW {
  81. PREPARE_UPDT 'msedgewebview' $WEBV_UID; PREPARE_UPDT 'msedgeupdate' $UPDT_UID
  82. $cfg = @{Register=$true; ForceApplicationShutdown=$true; ForceUpdateFromAnyVersion=$true; DisableDevelopmentMode=$true}
  83. dir "$env:SystemRoot\SystemApps\Microsoft.Win32WebViewHost*\AppxManifest.xml" -rec -ea 0 | Add-AppxPackage @cfg
  84. dir "$env:ProgramFiles\WindowsApps\MicrosoftWindows.Client.WebExperience*\AppxManifest.xml" -rec -ea 0 | Add-AppxPackage @cfg
  85. kill -name explorer -ea 0; if ((get-process -name 'explorer' -ea 0) -eq $null) {start explorer}
  86. }
  87. ## -------------------------------------------------------------------------------------------------------------------------------
  88. ## 2 enable admin privileges
  89. $D1=[uri].module.gettype('System.Diagnostics.Process')."GetM`ethods"(42) |where {$_.Name -eq 'SetPrivilege'} #`:no-ev-warn
  90. 'SeSecurityPrivilege','SeTakeOwnershipPrivilege','SeBackupPrivilege','SeRestorePrivilege'|foreach {$D1.Invoke($null, @("$_",2))}
  91. ## -------------------------------------------------------------------------------------------------------------------------------
  92. ## 3 shut down edge & webview clone stuff
  93. cd $env:systemdrive; taskkill /im explorer.exe /f 2>&1 >''
  94. $shut = 'explorer','Widgets','widgetservice','msedgewebview2','MicrosoftEdge*','chredge','msedge','edge'
  95. $shut,'msteams','msfamily','WebViewHost','Clipchamp' |foreach {kill -name $_ -force -ea 0}
  96. ## clear win32 uninstall block
  97. foreach ($name in $remove_win32) { foreach ($sw in $ALLHIVES) {
  98. $key = "$sw\Microsoft\Windows\CurrentVersion\Uninstall\$name"; if (-not (test-path $key)) {continue}
  99. foreach ($val in 'NoRemove','NoModify','NoRepair') {rp $key $val -force -ea 0}
  100. foreach ($val in 'ForceRemove','Delete') {sp $key $val 1 -type Dword -force}
  101. }}
  102. PREPARE_EDGE
  103. ## find all Edge setup.exe and gather BHO paths for OpenWebSearch / MSEdgeRedirect usage
  104. $edges = @(); $bho = @(); $edgeupdates = @(); 'LocalApplicationData','ProgramFilesX86','ProgramFiles' |foreach {
  105. $folder = [Environment]::GetFolderPath($_); $bho += dir "$folder\Microsoft\Edge*\ie_to_edge_stub.exe" -rec -ea 0
  106. if ($WEBV) {$edges += dir "$folder\Microsoft\Edge*\setup.exe" -rec -ea 0 |where {$_ -like '*EdgeWebView*'}}
  107. $edges += dir "$folder\Microsoft\Edge*\setup.exe" -rec -ea 0 |where {$_ -notlike '*EdgeWebView*'}
  108. $edgeupdates += dir "$folder\Microsoft\EdgeUpdate\*.*.*.*\MicrosoftEdgeUpdate.exe" -rec -ea 0
  109. }
  110. ## export OpenWebSearch innovative redirector - used by MSEdgeRedirect as well
  111. $DIR = "$env:SystemDrive\Scripts"; mkdir $DIR -ea 0 >''
  112. foreach ($b in $bho) { if (test-path $b) { try {copy $b "$DIR\ie_to_edge_stub.exe" -force -ea 0} catch{} } }
  113. ## -------------------------------------------------------------------------------------------------------------------------------
  114. ## 4 remove found *Edge* appx packages with unblock tricks
  115. $provisioned = get-appxprovisionedpackage -online; $appxpackage = get-appxpackage -allusers; $eol = @()
  116. $store = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore'
  117. $users = @('S-1-5-18'); if (test-path $store) {$users += $((dir $store -ea 0 |where {$_ -like '*S-1-5-21*'}).PSChildName)}
  118. foreach ($choice in $remove_appx) { if ('' -eq $choice.Trim()) {continue}
  119. foreach ($appx in $($provisioned |where {$_.PackageName -like "*$choice*"})) {
  120. $next = !1; foreach ($no in $skip) {if ($appx.PackageName -like "*$no*") {$next = !0}} ; if ($next) {continue}
  121. $PackageName = $appx.PackageName; $PackageFamilyName = ($appxpackage |where {$_.Name -eq $appx.DisplayName}).PackageFamilyName
  122. ni "$store\Deprovisioned\$PackageFamilyName" -force >''; $PackageFamilyName
  123. foreach ($sid in $users) {ni "$store\EndOfLife\$sid\$PackageName" -force >''} ; $eol += $PackageName
  124. dism /online /set-nonremovableapppolicy /packagefamily:$PackageFamilyName /nonremovable:0 >''
  125. remove-appxprovisionedpackage -packagename $PackageName -online -allusers >''
  126. }
  127. foreach ($appx in $($appxpackage |where {$_.PackageFullName -like "*$choice*"})) {
  128. $next = !1; foreach ($no in $skip) {if ($appx.PackageFullName -like "*$no*") {$next = !0}} ; if ($next) {continue}
  129. $PackageFullName = $appx.PackageFullName;
  130. ni "$store\Deprovisioned\$appx.PackageFamilyName" -force >''; $PackageFullName
  131. foreach ($sid in $users) {ni "$store\EndOfLife\$sid\$PackageFullName" -force >''} ; $eol += $PackageFullName
  132. dism /online /set-nonremovableapppolicy /packagefamily:$PackageFamilyName /nonremovable:0 >''
  133. remove-appxpackage -package $PackageFullName -allusers >''
  134. }
  135. }
  136. ## -------------------------------------------------------------------------------------------------------------------------------
  137. ## 5 run found *Edge* setup.exe with uninstall args and wait in-between
  138. foreach ($setup in $edges) { if (-not (test-path $setup)) {continue}
  139. if ($setup -like '*EdgeWebView*') {$target = "--msedgewebview"} else {$target = "--msedge"}
  140. $sulevel = ('--system-level','--user-level')[$setup -like '*\AppData\Local\*']
  141. $removal = "--uninstall $target $sulevel --verbose-logging --force-uninstall"
  142. try {write-host $setup $removal; start -wait $setup -args $removal} catch {}
  143. do {sleep 3} while ((get-process -name 'setup','MicrosoftEdge*' -ea 0).Path -like '*\Microsoft\Edge*')
  144. }
  145. ## -------------------------------------------------------------------------------------------------------------------------------
  146. ## msi installers cleanup
  147. gp 'HKLM:\SOFTWARE\Classes\Installer\Products\*' 'ProductName' |where {$_.ProductName -like '*Microsoft Edge*'} |foreach {
  148. $prod = ($_.PSChildName -split '(.{8})(.{4})(.{4})(.{4})' -join '-').trim('-')
  149. $sort = 7,6,5,4,3,2,1,0,8,12,11,10,9,13,17,16,15,14,18,20,19,22,21,23,25,24,27,26,29,28,31,30,33,32,35,34
  150. $code = '{' + -join ($sort |foreach {$prod[$_]}) + '}'; start -wait msiexec.exe -args "/X$code /qn" 2>''
  151. ri $_.PSPath -recurse -force
  152. foreach ($sw in $ALLHIVES) {ri "$sw\Microsoft\Windows\CurrentVersion\Uninstall\$code" -recurse -force}
  153. }
  154. ## 6 edgeupdate graceful cleanup
  155. if ($WEBV) {
  156. foreach ($sw in $ALLHIVES) {ri "$sw\Microsoft\EdgeUpdate" -recurse -force}
  157. foreach ($UPDT in $edgeupdates) {
  158. if (test-path $UPDT) {write-host "$UPDT /unregsvc"; start -wait $UPDT -args '/unregsvc'}
  159. do {sleep 3} while ((get-process -name 'setup','MicrosoftEdge*' -ea 0).Path -like '*\Microsoft\Edge*')
  160. if (test-path $UPDT) {write-host "$UPDT /uninstall"; start -wait $UPDT -args '/uninstall'}
  161. do {sleep 3} while ((get-process -name 'setup','MicrosoftEdge*' -ea 0).Path -like '*\Microsoft\Edge*')
  162. }
  163. Unregister-ScheduledTask -TaskName MicrosoftEdgeUpdate* -Confirm:$false -ea 0; ri "$PROGRAMS\Microsoft\Temp" -recurse -force
  164. }
  165. $appdata = $([Environment]::GetFolderPath('ApplicationData'))
  166. ri "$appdata\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Tombstones\Microsoft Edge.lnk" -force
  167. ri "$appdata\Microsoft\Internet Explorer\Quick Launch\Microsoft Edge.lnk" -force
  168. ## undo eol unblock trick to prevent latest cumulative update (LCU) failing
  169. foreach ($sid in $users) { foreach ($PackageName in $eol) {ri "$store\EndOfLife\$sid\$PackageName" -force >''} }
  170. ## .i. "Update policies are configured but will be ignored because this device isn't domain joined" .i.
  171. $uids = @($EDGE_UID); $cdps = @('msedge'); if ($WEBV) {$uids += $WEBV_UID; $cdps += 'msedgewebview'}
  172. foreach ($sw in $ALLHIVES) {
  173. sp "$sw\Microsoft\EdgeUpdate" 'DoNotUpdateToEdgeWithChromium' 1 -type Dword -force
  174. sp "$sw\Microsoft\EdgeUpdate" 'UpdaterExperimentationAndConfigurationServiceControl' 0 -type Dword -force
  175. sp "$sw\Microsoft\EdgeUpdate" 'InstallDefault' 0 -type Dword -force
  176. foreach ($uid in $uids) {
  177. sp "$sw\Microsoft\EdgeUpdate" "Install${uid}" 0 -type Dword -force
  178. sp "$sw\Microsoft\EdgeUpdate" "EdgePreview${uid}" 0 -type Dword -force
  179. sp "$sw\Microsoft\EdgeUpdate" "Update${uid}" 2 -type Dword -force
  180. foreach ($trigger in 'on-os-upgrade','on-logon','on-logon-autolaunch','on-logon-startup-boost') {
  181. sp "$sw\Microsoft\EdgeUpdate\Clients\${uid}\Commands\$trigger" 'AutoRunOnLogon' 0 -type Dword -force
  182. sp "$sw\Microsoft\EdgeUpdate\Clients\${uid}\Commands\$trigger" 'AutoRunOnOSUpgrade' 0 -type Dword -force
  183. sp "$sw\Microsoft\EdgeUpdate\Clients\${uid}\Commands\$trigger" 'Enabled' 0 -type Dword -force
  184. }
  185. }
  186. sp "$sw\Microsoft\MicrosoftEdge\Main" 'AllowPrelaunch' 0 -type Dword -force
  187. sp "$sw\Microsoft\MicrosoftEdge\TabPreloader" 'AllowTabPreloading' 0 -type Dword -force
  188. ## microsoft has no shame, so we are gonna insist opting-out of unsolicited reinstalls with windows updates
  189. foreach ($cdp in $cdps) { foreach ($arch in 'x64','x86') { foreach ($zdp in '','-zdp') {
  190. sp "$sw\Microsoft\EdgeUpdateDev\CdpNames" "$cdp-stable-win-$arch$zdp" "$cdp-stable-win-arm64$zdp" -force
  191. }}}
  192. }
  193. ## -------------------------------------------------------------------------------------------------------------------------------
  194. ## 7 add bundled OpenWebSearch script to redirect microsoft-edge: anti-competitive links to the default browser
  195. $MSEP = ($env:ProgramFiles,${env:ProgramFiles(x86)})[[Environment]::Is64BitOperatingSystem] + '\Microsoft\Edge\Application'
  196. $IFEO = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options'
  197. $MIN = ('--headless','--width 1 --height 1')[([environment]::OSVersion.Version.Build) -gt 25179]
  198. $CMD = "$env:systemroot\system32\conhost.exe $MIN" # AveYo: minimize prompt - see Terminal issue #13914
  199. ni "HKLM:\SOFTWARE\Classes\microsoft-edge\shell\open\command" -force >''
  200. sp "HKLM:\SOFTWARE\Classes\microsoft-edge" '(Default)' 'URL:microsoft-edge' -force
  201. sp "HKLM:\SOFTWARE\Classes\microsoft-edge" 'URL Protocol' '' -force
  202. sp "HKLM:\SOFTWARE\Classes\microsoft-edge" 'NoOpenWith' '' -force
  203. sp "HKLM:\SOFTWARE\Classes\microsoft-edge\shell\open\command" '(Default)' "`"$DIR\ie_to_edge_stub.exe`" %1" -force
  204. ni "HKLM:\SOFTWARE\Classes\MSEdgeHTM\shell\open\command" -force >''
  205. sp "HKLM:\SOFTWARE\Classes\MSEdgeHTM" 'NoOpenWith' '' -force
  206. sp "HKLM:\SOFTWARE\Classes\MSEdgeHTM\shell\open\command" '(Default)' "`"$DIR\ie_to_edge_stub.exe`" %1" -force
  207. ni "$IFEO\ie_to_edge_stub.exe\0" -force >''
  208. sp "$IFEO\ie_to_edge_stub.exe" 'UseFilter' 1 -type Dword -force
  209. sp "$IFEO\ie_to_edge_stub.exe\0" 'FilterFullPath' "$DIR\ie_to_edge_stub.exe" -force
  210. sp "$IFEO\ie_to_edge_stub.exe\0" 'Debugger' "$CMD $DIR\OpenWebSearch.cmd" -force
  211. ni "$IFEO\msedge.exe\0" -force >''
  212. sp "$IFEO\msedge.exe" 'UseFilter' 1 -type Dword -force
  213. sp "$IFEO\msedge.exe\0" 'FilterFullPath' "$MSEP\msedge.exe" -force
  214. sp "$IFEO\msedge.exe\0" 'Debugger' "$CMD $DIR\OpenWebSearch.cmd" -force
  215. ## new: automatically re-create the needed hardlink if edge is reinstalled
  216. $ta = New-ScheduledTaskAction -Execute '%Temp%\OpenWebSearchRepair.cmd'
  217. $tt = New-ScheduledTaskTrigger -Once -At 00:00; $ts = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries
  218. Register-ScheduledTask -TaskName 'OpenWebSearchRepair' -Action $ta -Trigger $tt -Settings $ts -RunLevel Highest -Force >''
  219. $OpenWebSearch = @$
  220. @title OpenWebSearch Redux & echo off & set ?= open start menu web search, widgets links or help in your chosen browser - by AveYo
  221. for /f %%E in ('"prompt $E$S& for %%e in (1) do rem"') do echo;%%E[2t 2>nul & rem AveYo: minimize prompt
  222. call :reg_var "HKCU\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice" ProgID ProgID
  223. if /i "%ProgID%" equ "MSEdgeHTM" echo;Default browser is set to Edge! Change it or remove OpenWebSearch script. & pause & exit /b
  224. call :reg_var "HKCR\%ProgID%\shell\open\command" "" Browser
  225. set Choice=& for %%. in (%Browser%) do if not defined Choice set "Choice=%%~."
  226. call :reg_var "HKCR\MSEdgeMHT\shell\open\command" "" FallBack
  227. set "Edge=" & for %%. in (%FallBack%) do if not defined Edge set "Edge=%%~."
  228. set "URI=" & set "URL=" & set "NOOP=" & set "PassTrough=%Edge:msedge=edge%"
  229. set "CLI=%CMDCMDLINE:"=``% "
  230. if defined CLI set "CLI=%CLI:*ie_to_edge_stub.exe`` =%"
  231. if defined CLI set "CLI=%CLI:*ie_to_edge_stub.exe =%"
  232. if defined CLI set "CLI=%CLI:*msedge.exe`` =%"
  233. if defined CLI set "CLI=%CLI:*msedge.exe =%"
  234. set "FIX=%CLI:~-1%"
  235. if defined CLI if "%FIX%"==" " set "CLI=%CLI:~0,-1%"
  236. if defined CLI set "RED=%CLI:microsoft-edge=%"
  237. if defined CLI set "URL=%CLI:http=%"
  238. if defined CLI set "ARG=%CLI:``="%"
  239. if "%CLI%" equ "%RED%" (set NOOP=1) else if "%CLI%" equ "%URL%" (set NOOP=1)
  240. if defined NOOP if not exist "%PassTrough%" echo;@mklink /h "%PassTrough%" "%Edge%" >"%Temp%\OpenWebSearchRepair.cmd"
  241. if defined NOOP if not exist "%PassTrough%" schtasks /run /tn OpenWebSearchRepair 2>nul >nul
  242. if defined NOOP if not exist "%PassTrough%" timeout /t 3 >nul
  243. if defined NOOP if exist "%PassTrough%" start "" "%PassTrough%" %ARG%
  244. if defined NOOP exit /b
  245. set "URL=%CLI:*microsoft-edge=%"
  246. set "URL=http%URL:*http=%"
  247. set "FIX=%URL:~-2%"
  248. if defined URL if "%FIX%"=="``" set "URL=%URL:~0,-2%"
  249. call :dec_url
  250. start "" "%Choice%" "%URL%"
  251. exit
  252. :reg_var [USAGE] call :reg_var "HKCU\Volatile Environment" value-or-"" variable [extra options]
  253. set {var}=& set {reg}=reg query "%~1" /v %2 /z /se "," /f /e& if %2=="" set {reg}=reg query "%~1" /ve /z /se "," /f /e
  254. for /f "skip=2 tokens=* delims=" %%V in ('%{reg}% %4 %5 %6 %7 %8 %9 2^>nul') do if not defined {var} set "{var}=%%V"
  255. if not defined {var} (set {reg}=& set "%~3="& exit /b) else if %2=="" set "{var}=%{var}:*) =%"& rem AveYo: v3
  256. if not defined {var} (set {reg}=& set "%~3="& exit /b) else set {reg}=& set "%~3=%{var}:*) =%"& set {var}=& exit /b
  257. :dec_url brute url percent decoding by AveYo
  258. set ".=%URL:!=}%"&setlocal enabledelayedexpansion& rem brute url percent decoding
  259. set ".=!.:%%={!" &set ".=!.:{3A=:!" &set ".=!.:{2F=/!" &set ".=!.:{3F=?!" &set ".=!.:{23=#!" &set ".=!.:{5B=[!" &set ".=!.:{5D=]!"
  260. set ".=!.:{40=@!"&set ".=!.:{21=}!" &set ".=!.:{24=$!" &set ".=!.:{26=&!" &set ".=!.:{27='!" &set ".=!.:{28=(!" &set ".=!.:{29=)!"
  261. set ".=!.:{2A=*!"&set ".=!.:{2B=+!" &set ".=!.:{2C=,!" &set ".=!.:{3B=;!" &set ".=!.:{3D==!" &set ".=!.:{25=%%!"&set ".=!.:{20= !"
  262. set ".=!.:{=%%!" &rem set ",=!.:%%=!" & if "!,!" neq "!.!" endlocal& set "URL=%.:}=!%" & call :dec_url
  263. endlocal& set "URL=%.:}=!%" & exit /b
  264. rem done
  265. $@
  266. [io.file]::WriteAllText("$DIR\OpenWebSearch.cmd", $OpenWebSearch)
  267. ## -------------------------------------------------------------------------------------------------------------------------------
  268. ## 8 done
  269. $done = gp 'Registry::HKEY_Users\S-1-5-21*\Volatile*' Edge_Removal -ea 0; if ($done) {rp $done.PSPath Edge_Removal -force -ea 0}
  270. if ((get-process -name 'explorer' -ea 0) -eq $null) {start explorer}
  271. ## bonus enter into powershell console: firefox / edge / webview to install a browser / reinstall edge or webview after removal
  272. ${.} = [char]27; $firefox = "${.}[38;2;255;165;0m firefox"; $reinstall = "${.}[96m edge / webview / xsocial${.}[97m "
  273. write-host "`n${.}[40;32m EDGE REMOVED! ${.}[97m -GET-ANOTHER-BROWSER? ENTER:$firefox ${.}[97m -REINSTALL? ENTER:$reinstall"
  274. ## -------------------------------------------------------------------------------------------------------------------------------
  275. ## 0 ask to run script as admin
  276. '@.replace("$@","'@").replace("@$","@'") -force -ea 0; $code='gp ''Registry::HKEY_Users\S-1-5-21*\Volatile*'' Edge_Removal -ea 0'
  277. start powershell -args "-nop -noe -c & {iex(($code)[0].Edge_Removal)}" -verb runas
  278. #::