I need to be able to launch the default Windows browser, without specifying a URL (should open to home page).
我需要能够启动默认的Windows浏览器,而无需指定URL(应该打开主页)。
The solution should preferably not require compiling a binary (so a .bat, .vbs, or the like).
解决方案最好不要求编译二进制文件(例如.bat,.vbs等)。
It should also work on Win7+ through Win10 without installing any software, and without admin rights.
它也适用于Win7 +到Win10,无需安装任何软件,也没有管理员权限。
I have seen solutions that specify a URL, but that will not work for me. Is this possible ?
Thanks !
我见过指定URL的解决方案,但这对我不起作用。这可能吗 ?谢谢 !
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.
答案批处理 - 默认浏览器?不是重复,因为该答案为您提供了打开html文件的默认应用程序,而不是URL处理的默认浏览器。
3 个解决方案
#1
1
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).
以下只是部分答案,它仅查看当前用户注册表并相应地回应响应。 (从第12行删除Echo =然后删除第6行以实际尝试打开浏览器)。
@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).
这只是一个部分答案,因为如果当前用户没有更改其默认浏览器,则键/数据可能不存在。 (此时检查将更加复杂)。
#2
0
You can try this solution from here :
您可以从这里尝试此解决方案:
@echo off
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 "REG_SZ"') 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"
echo "%browser%"
Start "Default Browser" "%browser%"
pause>nul
Edit :28/03/2017 @ 01:55
编辑:28/03/2017 @ 01:55
Just give a try for this code :
试试这段代码吧:
@echo off
for /f "tokens=3 delims= " %%a in (
'REG QUERY "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\UserChoice" ^| FIND /i "ProgId"'
) Do (
set "input=%%a"
)
SET Browser=%input:~0,-4%.exe
echo "%Browser%"
Start "Default Browser" "%Browser%" & pause & exit
#3
0
Solved it with help from @Compo
在@Compo的帮助下解决了这个问题
Dim oShell
Set oShell = CreateObject("WScript.Shell")
Dim strProgId
strProgId = oShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice\ProgID")
Dim strExe
strExe = oShell.RegRead("HKEY_CLASSES_ROOT\" & strProgId & "\shell\open\command\")
wscript.echo strExe
#1
1
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).
以下只是部分答案,它仅查看当前用户注册表并相应地回应响应。 (从第12行删除Echo =然后删除第6行以实际尝试打开浏览器)。
@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).
这只是一个部分答案,因为如果当前用户没有更改其默认浏览器,则键/数据可能不存在。 (此时检查将更加复杂)。
#2
0
You can try this solution from here :
您可以从这里尝试此解决方案:
@echo off
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 "REG_SZ"') 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"
echo "%browser%"
Start "Default Browser" "%browser%"
pause>nul
Edit :28/03/2017 @ 01:55
编辑:28/03/2017 @ 01:55
Just give a try for this code :
试试这段代码吧:
@echo off
for /f "tokens=3 delims= " %%a in (
'REG QUERY "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\UserChoice" ^| FIND /i "ProgId"'
) Do (
set "input=%%a"
)
SET Browser=%input:~0,-4%.exe
echo "%Browser%"
Start "Default Browser" "%Browser%" & pause & exit
#3
0
Solved it with help from @Compo
在@Compo的帮助下解决了这个问题
Dim oShell
Set oShell = CreateObject("WScript.Shell")
Dim strProgId
strProgId = oShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice\ProgID")
Dim strExe
strExe = oShell.RegRead("HKEY_CLASSES_ROOT\" & strProgId & "\shell\open\command\")
wscript.echo strExe