1

I am writing a batch file and I need to start chrome exe using that batch file . So for that I need to get the path of the directory where chrome is installed .

Usually it is installed in " C:\Program Files (x86)\Google\Chrome\Application" but some users change the path while they install chrome.

I will like to get the path of that chrome exe on run time using command prompt and start it from there.

The content of my batch file are : Where for the highlighted code I want to get on run time instead of hard coding it into my .bat file

(I took help of this to get admin rights.)

@echo 
:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B
:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"
:----------------------https://stackoverflow.com/questions/1894967/how-to-request-administrator-access-inside-a-batch-file----------------
echo Closing all instances of chrome.....
taskkill /f /im chrome.exe
echo All instances of chrome closed. Now going to chrome exe location 

cd **C:\Program Files (x86)\Google\Chrome\Application**
echo Reached to chrome exe location. Ready to start new chrome with web security off.
chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security
Community
  • 1
  • 1
ManishT
  • 11
  • 1
  • 6

1 Answers1

3

Get the installed location of Google Chrome from the registry

"HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\shell\open\command"
"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Clients\StartMenuInternet\Google Chrome\shell\open\command"

Example:

set "Command="
for /f "tokens=2,*" %%A in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\shell\open\command" /ve 2^>nul') do set "Command=%%~B"
if not defined Command for /f "tokens=2,*" %%A in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Clients\StartMenuInternet\Google Chrome\shell\open\command" /ve 2^>nul') do set "Command=%%~B"
if not defined Command echo Google Chrome was not found.
if defined Command start "Browser" "%Command%"
David Ruhmann
  • 11,064
  • 4
  • 37
  • 47
  • It works fine on my machine but not on other machine as the reg values are different on the other machine. I dont know the reason. But it helped me a lot . One thing I need to ask u .I am sure that answer is no but asking for confirmation.. Can we have different reg entries in different machines ? – ManishT Oct 09 '14 at 19:05
  • Depending on how the user installed the browser, it could also be under the HKEY_CURRENT_USER tree. See [How to Register an Internet Browser or Email Client With the Windows Start Menu](http://msdn.microsoft.com/en-us/library/windows/desktop/dd203067.aspx) – David Ruhmann Oct 09 '14 at 19:10