Reputation: 71
Hello i am developing a application using selenium and python 3.7 to automatically update the browser driver by getting old version and new version from browser's website and i want this for other chrome builds also like canary etc... i am new to command-line and registry so i am unable to figure it out.
i have also tried this code :-
@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
Output:- But does not show location for chrome dev
INSTALLED BROWSERS
Firefox-308046B0AF4A39CB
Google Chrome
Google Chrome Dev
IEXPLORE
Microsoft Edge
EXECUTABLES PATHS
C:\Program Files\Internet Explorer\iexplore.exe
C:\Program Files\Mozilla Firefox\firefox.exe
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
DEFAULT BROWSER
iexplore
DEFAULT .HTML VIEWER
iexplore
Press any key to continue . . .
Upvotes: 1
Views: 1316
Reputation: 5372
@echo off
echo:
echo INSTALLED BROWSERS
echo:
for /f "delims=" %%A in (
'reg query HKLM\SOFTWARE\Clients\StartMenuInternet /k /f *'
) do (
for /f "tokens=1,2,*" %%B in (
'2^>nul reg query "%%~A\defaulticon" /ve ^| findstr /v "^HKEY"'
) do (
echo "%%~nD"
)
)
echo:
echo EXECUTABLES PATHS
echo:
for /f "delims=" %%A in (
'reg query HKLM\SOFTWARE\Clients\StartMenuInternet /k /f *'
) do (
for /f "tokens=1,2,*" %%B in (
'2^>nul reg query "%%~A\shell\open\command" /ve ^| findstr /v "^HKEY"'
) do (
echo "%%~D"
)
)
echo:
echo DEFAULT BROWSER
echo:
for /f "tokens=1,2,*" %%A in (
'reg query HKCR\http\shell\open\command /ve ^| findstr /v "^HKEY"'
) do (
echo "%%~nC"
)
echo:
echo DEFAULT .HTML VIEWER
echo:
for /f "tokens=1,2,*" %%A in (
'reg query HKCR\htmlfile\shell\open\command /ve ^| findstr /v "^HKEY"'
) do (
echo "%%~nC"
)
echo:
pause
Can eliminate use of temporary files with reg query
and avoid regedit
which may require administrator privileges.
The output is double quoted though you can remove the quotes if desired.
No named variables are used so setlocal
is not used.
I do not have Chrome Dev installed so testing if detected is unknown from my current environment so I will show the output I do get on Windows 7:
INSTALLED BROWSERS "firefox" "chrome" "iexplore" EXECUTABLES PATHS "C:\Program Files\Mozilla Firefox\firefox.exe" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "C:\Program Files\Internet Explorer\iexplore.exe" DEFAULT BROWSER "iexplore" DEFAULT .HTML VIEWER "iexplore" Press any key to continue . . .
If you want browser versions, this example for Firefox version may help guide the way:
for /f "tokens=1,2,*" %%A in (
'2^>nul reg query "HKLM\SOFTWARE\Mozilla\Mozilla Firefox" /ve ^| findstr /v "^HKEY"'
) do (
echo "%%~C"
)
Upvotes: 1
Reputation: 3112
@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=%%~fB"
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=%%~fB"
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
This should solve your issue with Chrome Dev
, however, there are some errors with the DEFAULT BROWSER
and DEFAULT HTML VIEWER
sections of the file which I do not understand why it doesn't work. One thing that I noticed with my default html handler and browser, Brave, they create their own html tag Brave HTML Document
which is separate to htmlfile
in the registry and ftype
command. ftype
output for me shows Brave HTML file
alone and iexplorer
as my default html and https handler which both are incorrect. I don't know why this is and I want to know as well but since that is a different problem, you should ask a different question for it.
Upvotes: 1