Search code examples
windowsbatch-filevbscriptregistry

Launch default Windows browser without URL from .bat/.vbs?


I need to be able to launch the default Windows browser, without specifying a URL (should open to home page).

The solution should preferably not require compiling a binary (so a .bat, .vbs, or the like).

It should also work on Win7+ through Win10 without installing any software, and without admin rights.

I have seen solutions that specify a URL, but that will not work for me. Is this possible ?
Thanks !

The answer Batch - Default Browser? is not a duplicate because that answer gives you the default application to open html files, not the default browser for URL handling.


Solution

  • The following is only a part answer, it looks only at the current user registry and echoes the response accordingly. (Remove Echo= from line 12 then delete line 6 to actually attempt to open the browser).

    @Echo Off
    Set "RK1=HKCU\Software\Microsoft\Windows\Shell\Associations"
    Set "RK1=%RK1%\UrlAssociations\http\UserChoice"
    Set "RK2=HKCU\Software\Classes\%%B\shell\open\command"
    Call :Sub
    Timeout -1
    GoTo :EOF
    
    :Sub    
    For /F "Tokens=2*" %%A In ('Reg Query "%RK1%" /V Progid 2^>Nul') Do (
        For /F "Tokens=2*" %%C In ('Reg Query "%RK2%" /VE 2^>Nul') Do (
            For %%E In (%%D) Do If Exist "%%~E" Echo=Start "" "%%~E"))
    GoTo :EOF
    

    It is only a part answer because if the current user hasn't changed their default browser that key/data may not exist. (At that point the checks would become more involved).