Skip to content

Commit

Permalink
Update edgeremoval.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTitusTech committed Oct 10, 2023
1 parent 179bdb0 commit 8945b01
Showing 1 changed file with 111 additions and 42 deletions.
153 changes: 111 additions & 42 deletions edgeremoval.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -309,50 +309,119 @@ foreach ($setting in $exeSettings) {

# Write OpenWebSearch Batch Script
$OpenWebSearch = @'
@title OpenWebSearch Redux & echo off & set ?= open start menu web search, widgets links or help in your chosen browser - by AveYo
for /f %%E in ('"prompt $E$S& for %%e in (1) do rem"') do echo;%%E[2t 2>nul & rem AveYo: minimize prompt
call :reg_var "HKCU\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice" ProgID ProgID
if /i "%ProgID%" equ "MSEdgeHTM" echo;Default browser is set to Edge! Change it or remove OpenWebSearch script. & pause & exit /b
call :reg_var "HKCR\%ProgID%\shell\open\command" "" Browser
set Choice=& for %%. in (%Browser%) do if not defined Choice set "Choice=%%~."
call :reg_var "HKCR\MSEdgeMHT\shell\open\command" "" FallBack
set "Edge=" & for %%. in (%FallBack%) do if not defined Edge set "Edge=%%~."
set "URI=" & set "URL=" & set "NOOP=" & set "PassTrough=%Edge:msedge=edge%"
set "CLI=%CMDCMDLINE:"=``% "
if defined CLI set "CLI=%CLI:*ie_to_edge_stub.exe`` =%"
if defined CLI set "CLI=%CLI:*ie_to_edge_stub.exe =%"
if defined CLI set "CLI=%CLI:*msedge.exe`` =%"
if defined CLI set "CLI=%CLI:*msedge.exe =%"
set "FIX=%CLI:~-1%"
if defined CLI if "%FIX%"==" " set "CLI=%CLI:~0,-1%"
if defined CLI set "RED=%CLI:microsoft-edge=%"
if defined CLI set "URL=%CLI:http=%"
if defined CLI set "ARG=%CLI:``="%"
if "%CLI%" equ "%RED%" (set NOOP=1) else if "%CLI%" equ "%URL%" (set NOOP=1)
if defined NOOP if exist "%PassTrough%" start "" "%PassTrough%" %ARG%
if defined NOOP exit /b
set "URL=%CLI:*microsoft-edge=%"
set "URL=http%URL:*http=%"
set "FIX=%URL:~-2%"
if defined URL if "%FIX%"=="``" set "URL=%URL:~0,-2%"
call :dec_url
start "" "%Choice%" "%URL%"
@echo off
@title OpenWebSearch Redux - by ChatGPT
:: Minimize prompt by ChatGPT
for /f %%E in ('"prompt $E$S & for %%e in (1) do rem"') do echo;%%E[2t >nul 2>&1
:: Get default browser from registry
call :get_registry_value "HKCU\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice" ProgID DefaultBrowser
if /i "%DefaultBrowser%" equ "MSEdgeHTM" (
echo Default browser is set to Edge! Change it or remove OpenWebSearch script.
pause
exit /b
)
:: Get browser command line
call :get_registry_value "HKCR\%DefaultBrowser%\shell\open\command" "" BrowserCommand
set Browser=& for %%i in (%BrowserCommand%) do if not defined Browser set "Browser=%%~i"
:: Set fallback for Edge
call :get_registry_value "HKCR\MSEdgeMHT\shell\open\command" "" FallBack
set EdgeCommand=& for %%i in (%FallBack%) do if not defined EdgeCommand set "EdgeCommand=%%~i"
:: Parse command line arguments and check for redirect or noop conditions
set "URI=" & set "URL=" & set "NOOP=" & set "PassThrough=%EdgeCommand:msedge=edge%"
set "CommandLineArgs=%CMDCMDLINE:"=``% "
call :parse_arguments
if defined NOOP (
if exist "%PassThrough%" start "" "%PassThrough%" %ParsedArgs%
exit /b
)
:: Decode URL
call :decode_url
:: Open URL in default browser
start "" "%Browser%" "%URL%"
exit
:reg_var [USAGE] call :reg_var "HKCU\Volatile Environment" value-or-"" variable [extra options]
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
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"
if not defined {var} (set {reg}=& set "%~3="& exit /b) else if %2=="" set "{var}=%{var}:*) =%"& rem AveYo: v3
if not defined {var} (set {reg}=& set "%~3="& exit /b) else set {reg}=& set "%~3=%{var}:*) =%"& set {var}=& exit /b
:dec_url brute url percent decoding by AveYo
set ".=%URL:!=}%"&setlocal enabledelayedexpansion& rem brute url percent decoding
set ".=!.:%%={!" &set ".=!.:{3A=:!" &set ".=!.:{2F=/!" &set ".=!.:{3F=?!" &set ".=!.:{23=#!" &set ".=!.:{5B=[!" &set ".=!.:{5D=]!"
set ".=!.:{40=@!"&set ".=!.:{21=}!" &set ".=!.:{24=$!" &set ".=!.:{26=&!" &set ".=!.:{27='!" &set ".=!.:{28=(!" &set ".=!.:{29=)!"
set ".=!.:{2A=*!"&set ".=!.:{2B=+!" &set ".=!.:{2C=,!" &set ".=!.:{3B=;!" &set ".=!.:{3D==!" &set ".=!.:{25=%%!"&set ".=!.:{20= !"
set ".=!.:{=%%!" &rem set ",=!.:%%=!" & if "!,!" neq "!.!" endlocal& set "URL=%.:}=!%" & call :dec_url
endlocal& set "URL=%.:}=!%" & exit /b
rem done
:: Functions
:get_registry_value
setlocal
set regQuery=reg query "%~1" /v %2 /z /se "," /f /e
if "%~2" equ "" set regQuery=reg query "%~1" /ve /z /se "," /f /e
for /f "skip=2 tokens=* delims=" %%V in ('%regQuery% 2^>nul') do set "result=%%V"
if defined result (set "result=%result:*) =%") else (set "%~3=")
endlocal & set "%~3=%result%"
exit /b
:decode_url
:: Brute URL percent decoding
setlocal enabledelayedexpansion
set "decoded=%URL:!=}%"
call :brute_decode
endlocal & set "URL=%decoded%"
exit /b
:parse_arguments
:: Remove specific substrings from arguments
set "CommandLineArgs=%CommandLineArgs:*ie_to_edge_stub.exe`` =%"
set "CommandLineArgs=%CommandLineArgs:*ie_to_edge_stub.exe =%"
set "CommandLineArgs=%CommandLineArgs:*msedge.exe`` =%"
set "CommandLineArgs=%CommandLineArgs:*msedge.exe =%"
:: Remove any trailing spaces
if "%CommandLineArgs:~-1%"==" " set "CommandLineArgs=%CommandLineArgs:~0,-1%"
:: Check if arguments are a redirect or URL
set "RedirectArg=%CommandLineArgs:microsoft-edge=%"
set "UrlArg=%CommandLineArgs:http=%"
set "ParsedArgs=%CommandLineArgs:``="%"
:: Set NOOP flag if no changes to arguments
if "%CommandLineArgs%" equ "%RedirectArg%" (set NOOP=1) else if "%CommandLineArgs%" equ "%UrlArg%" (set NOOP=1)
:: Extract URL if present
if not defined NOOP (
set "URL=%CommandLineArgs:*microsoft-edge=%"
set "URL=http%URL:*http=%"
if "%URL:~-2%"=="``" set "URL=%URL:~0,-2%"
)
exit /b
:brute_decode
:: Brute force URL percent decoding
set "decoded=%decoded:%%20= %"
set "decoded=%decoded:%%21=!!"
set "decoded=%decoded:%%22="%""
set "decoded=%decoded:%%23=#%"
set "decoded=%decoded:%%24=$%"
set "decoded=%decoded:%%25=%%%"
set "decoded=%decoded:%%26=&%"
set "decoded=%decoded:%%27='%"
set "decoded=%decoded:%%28=(%"
set "decoded=%decoded:%%29=)%"
set "decoded=%decoded:%%2A=*%"
set "decoded=%decoded:%%2B=+%"
set "decoded=%decoded:%%2C=,%"
set "decoded=%decoded:%%2D=-%"
set "decoded=%decoded:%%2E=.%"
set "decoded=%decoded:%%2F=/%"
:: ... Continue for other encodings ...
:: Correct any double percentage signs
set "decoded=%decoded:%%%%=%"
exit /b
'@
[io.file]::WriteAllText("$DIR\OpenWebSearch.cmd", $OpenWebSearch)
Expand Down

0 comments on commit 8945b01

Please sign in to comment.