(view source code of getdefaultbrowser.bat as plain text)
@ECHO OFF
:: No command line arguments accepted except /Q
IF NOT "%~1"=="" IF /I NOT "%~1"=="/Q" GOTO Syntax
SETLOCAL ENABLEDELAYEDEXPANSION
SET DefaultBrowser=
SET QuietMode=0
IF /I "%~1"=="/Q" SET QuietMode=1
FOR /F "tokens=2*" %%A IN ('REG.EXE Query "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\UserChoice" /V ProgID') DO (
FOR /F "tokens=2*" %%C IN ('REG.EXE Query "HKEY_CLASSES_ROOT\%%~B\shell\open\command"') DO (
SET Executable=
FOR %%E IN (%%D) DO IF "!Executable!"=="" SET Executable="%%~E"
)
FOR /F "delims=-" %%C IN ("%%~B") DO (
SET DefaultBrowser=%%~C
SET DefaultBrowser=!DefaultBrowser:HTML=!
SET DefaultBrowser=!DefaultBrowser:HTM=!
SET DefaultBrowser=!DefaultBrowser:URL=!
)
IF %QuietMode% EQU 0 (
ECHO.
ECHO For local .html files:
ECHO Default browser = !DefaultBrowser!
ECHO Program Path = !Executable!
)
)
FOR /F "tokens=2*" %%A IN ('REG.EXE Query "HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice" /V ProgID') DO (
FOR /F "tokens=2*" %%C IN ('REG.EXE Query "HKEY_CLASSES_ROOT\%%~B\shell\open\command"') DO (
SET Executable=
FOR %%E IN (%%D) DO IF "!Executable!"=="" SET Executable="%%~E"
)
FOR /F "delims=-" %%C IN ("%%~B") DO (
SET DefaultBrowser=%%~C
SET DefaultBrowser=!DefaultBrowser:HTML=!
SET DefaultBrowser=!DefaultBrowser:HTM=!
SET DefaultBrowser=!DefaultBrowser:URL=!
)
IF %QuietMode% EQU 0 (
ECHO.
ECHO For http and https URLs:
ECHO Default browser = !DefaultBrowser!
ECHO Program Path = !Executable!
)
)
ENDLOCAL & SET DefaultBrowser=%DefaultBrowser%
EXIT /B 0
:Syntax
ECHO.
ECHO GetDefaultBrowser.bat, Version 1.03 for Windows 10/11
ECHO Demo script to try and detect the default browser
ECHO.
ECHO Usage: GetDefaultBrowser.bat [ /Q ]
ECHO.
ECHO Where: /Q forces Quiet mode, i.e. no screen output, only environment variable
ECHO.
ECHO Note: This batch file searches the registry for the user's default browser
ECHO choice, first for local .html files, next for http(s) URLs.
ECHO The latter value will be stored in an environment variable named
ECHO DefaultBrowser.
ECHO The default browser's name and path are displayed unless /Q is used.
ECHO Return code ("ErrorLevel") 1 on command line errors, otherwise 0.
ECHO.
ECHO Credits: Joe Caverly (.html) and Steve Robertson (URLs).
ECHO.
ECHO Written by Rob van der Woude
ECHO https://www.robvanderwoude.com
EXIT /B 1
page last modified: 2024-04-16; loaded in 0.0058 seconds