Batch - Default Browser?

前端 未结 8 1116
北荒
北荒 2021-02-12 16:09

Is there a way for using a batch file to find the default browser on my computer?

8条回答
  •  渐次进展
    2021-02-12 16:45

    I hope this helps someone. I needed to start the default browser with a html file.

    @echo off
    setlocal
    
    rem setup a default browser in case we fail
    set default_browser=C:\Program Files\Internet Explorer\iexplore.exe
    
    rem look in the HKEY_CLASSES_ROOT\htmlfile\shell\open\command registry for the default browser
    for /f "tokens=*" %%a in ('REG QUERY HKEY_CLASSES_ROOT\htmlfile\shell\open\command /ve ^| FIND /i "default"') do (
       set input=%%a
    )
    setlocal enableDelayedExpansion
    
    rem parse the input field looking for the second token
    for /f tokens^=^2^ eol^=^"^ delims^=^" %%a in ("!input!") do set browser=%%a
    
    setlocal disableDelayedExpansion
    
    rem this may not be needed, check if reg returned a real file, if not unset browser
    if not "%browser%" == "" if not exist "%browser%" set browser=
    if "%browser%"=="" set browser=%default_browser%
    "%browser%" index.html
    endlocal
    

提交回复
热议问题