我需要通过运行.bat文件来检查任何Windows系统中的可用浏览器。批处理文件应该能够检查系统中是否安装了Firefox和Chrome或任何其他浏览器。否则我想打开默认浏览器。
if exist "C:\Program Files(x86)\Mozilla Firefox\firefox.exe" start firefox.exe
这是一种方法,但如果安装在其他位置完成,则无法正常工作。
答案 0 :(得分:3)
我建议使用HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet
键。它列出了已在系统上注册的Web浏览器客户端,并提供了哪一个是默认设置,以及在系统中找到每个客户端的位置。
有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/windows/desktop/dd203067(v=vs.85).aspx。
这里只是一个例子,我把它们放在一起来说明如何使用这些信息。根据您的需要或根据您的要求进行调整。
@echo off
setlocal EnableDelayedExpansion
:Menu
echo 32-bit
set "Count=1"
for /f "tokens=2,*" %%A in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Clients\StartMenuInternet" /ve 2^>nul') do set "Default=%%B"
for /f "skip=3 delims=" %%A in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Clients\StartMenuInternet" 2^>nul') do (
if "%%~nxA"=="%Default%" (
echo !Count!. %%~nA [Default]
) else (
echo !Count!. %%~nA
)
set /a "Count+=1"
)
echo.
echo 64-bit if 32-bit above, else 32-bit
for /f "tokens=2,*" %%A in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet" /ve 2^>nul') do set "Default=%%B"
for /f "skip=3 delims=" %%A in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet" 2^>nul') do (
if "%%~nxA"=="%Default%" (
echo !Count!. %%~nA [Default]
) else (
echo !Count!. %%~nA
)
set /a "Count+=1"
)
echo.
:Input
set "Input="
set /p "Input=> Select a Browser: "
if not defined Input goto Input
set "Input=%Input:"=%"
set "Count=1"
:: NOTE if the browser name is typed out and matching on the name then the last match will be chosen.
:: As it is currently setup this means that the 32-bit version will always win on a name match.
for /f "skip=3 delims=" %%A in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet" 2^>nul') do (
if /i "%Input%"=="%%~nA" set "Choice=%%~A"
if "%Input%"=="!Count!" set "Choice=%%~A"
set /a "Count+=1"
)
for /f "skip=3 delims=" %%A in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Clients\StartMenuInternet" 2^>nul') do (
if /i "%Input%"=="%%~nA" set "Choice=%%~A"
if "%Input%"=="!Count!" set "Choice=%%~A"
set /a "Count+=1"
)
if not defined Choice goto Menu
for /f "tokens=2,*" %%A in ('reg query "%Choice%\shell\open\command" /ve 2^>nul') do set "Command=%%~B"
start "Browser" "%Command%"
endlocal
echo Done
pause>nul
答案 1 :(得分:0)
您最终需要以管理员身份启动它,因为它从注册表中导出值。我没有使用REG命令来实现最大兼容性:
@echo off
START /W REGEDIT /E "%Temp%.\BROW.reg" HKEY_CURRENT_USER\Software\Classes
setlocal enableDelayedExpansion
for /f "tokens=4 delims=\" %%B in ('type %Temp%.\BROW.reg ^| findstr /E "HTML\shell]"') do (
set "browser=%%B"
echo !browser:~0,-4!
)
endlocal
del /Q /F "%Temp%.\BROW.reg"
修改强>
@echo off
setlocal enableExtensions
echo.
echo.
echo INSTALLED BROWSERS
echo.
echo.
rem :::::::::::::::::::::::::::::::::::::::::::::::::::::
rem :: exporting registry values for installed browsers
rem :::::::::::::::::::::::::::::::::::::::::::::::::::::
rem for 64 bit systems
START /W REGEDIT /E "%Temp%\BROW3.reg" HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Clients\StartMenuInternet
rem for 32 bit systems
if not exist "%Temp%\BROW3.reg" START /W REGEDIT /E "%Temp%\BROW3.reg" HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet
setLocal enableDelayedExpansion
for /f "tokens=*" %%B in ('type "%Temp%\BROW3.reg" ^| findstr /E "DefaultIcon]"') do (
rem extracting browser name from icon path
set "browser=%%B"
rem removing \DefaultIcon] string
set "browser=!browser:\DefaultIcon]=!"
rem get the browser name
for %%P in ("!browser!") do echo %%~nP
)
endLocal
echo.
echo.
echo EXECUTABLES PATHS
echo.
echo.
setLocal enableDelayedExpansion
for /f "tokens=* delims=@=" %%B in ('type "%Temp%\BROW3.reg" ^| findstr /B "@" ^| findstr /E ".exe\\\",0\"^"') do (
set "browser=%%~B"
set "browser=!browser:\\=\!"
echo !browser!
)
setLocal enableDelayedExpansion
for /f "tokens=* delims=@=" %%B in ('type "%Temp%\BROW3.reg" ^| findstr /B "@" ^| findstr /E ".exe,0\"^"') do (
set "browser=%%~B"
set "browser=!browser:\\=\!"
set "browser=!browser:,0=!"
echo !browser!
)
endLocal
rem delete temp file
del /Q /F "%Temp%\BROW3.reg"
echo.
echo.
echo DEFAULT BROWSER
echo.
echo.
START /W REGEDIT /E "%Temp%\BROW5.reg" HKEY_CLASSES_ROOT\http\shell\open\command
setLocal enableDelayedExpansion
for /f tokens^=3^ delims^=^" %%B in ('type "%Temp%\BROW5.reg" ^| find "@"') do (
set "default=%%B"
rem removing double slashes
set "default=!default:\\=\!"
rem removing end slash
set "default=!default:~0,-1!"
rem get the name
for %%D in ("!default!") do echo %%~nD
)
endLocal
del /Q /F "%Temp%\BROW5.reg"
echo.
echo.
echo DEFAULT .HTML VIEWER
echo.
echo.
START /W REGEDIT /E "%Temp%\BROW6.reg" HKEY_CLASSES_ROOT\htmlfile\shell\open\command
setLocal enableDelayedExpansion
for /f tokens^=3^ delims^=^" %%B in ('type "%Temp%\BROW6.reg" ^| find "@"') do (
set "default=%%B"
set "default=!default:\\=\!"
set "default=!default:~0,-1!"
for %%D in ("!default!") do echo %%~nD
)
endLocal
del /Q /F "%Temp%\BROW6.reg"
echo.
echo.
pause