2

I need to check for the chrome browser in any Windows system by running a .bat file. The batch file should be able to check if Chrome browser is installed in the system. if its installed want to store the path in a variable and use that.I am creating chrome kiosk app..so need to find the chrome path dynamically.Please help me

start  "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --kiosk --fullscreen --incognito "website url" 
Gerhard
  • 22,678
  • 7
  • 27
  • 43
learner
  • 331
  • 1
  • 9
  • 22
  • `where chrome` assuming it is installed properly. – Gerhard Apr 20 '18 at 06:46
  • if user change the chrome default installed location,i want to identify that location dynamically when i strat bat file.that's my requirement..in windows 10 the default location is C:\Program Files (x86)\Google\Chrome\Application\chrome.exe,but windows 7 it is different.. – learner Apr 20 '18 at 06:47
  • have you tried `where chrome` ? – Gerhard Apr 20 '18 at 06:48
  • i am using windows 10,here its installed in C:\Program Files (x86)\Google\Chrome\Application\chrome.exe.. – learner Apr 20 '18 at 06:49
  • no, I am asking, have you tried the command? open `cmd.exe` and type `where chrome` then press enter – Gerhard Apr 20 '18 at 06:50
  • i am using .bat file ..not windows cmd.. – learner Apr 20 '18 at 06:51
  • Batch files are files that stores batches of commands.. anyway, see my answer. – Gerhard Apr 20 '18 at 06:52

2 Answers2

2

After our discussion in chat, we found that if chrome is not installed, it will not launch. therefore simply use:

start "" "chrome" --kiosk --fullscreen --incognito "https://www.netflix.com/"

We need to ensure that all other chrome windows are closed as it will not open kiosk mode if chrome is already open.

That means if chrome is not found by default using start it is not installed.

Older tries:

This batch file is assuming chrome is installed correctly:

for /F "delims=" %%a in ('where chrome') do (
start "" "%%a" --kiosk --fullscreen --incognito "website url"
)
pause

Once you confirmed that it is working, simply remove echo from the last line to actually perform the start.

The next option, seeing as where might not work is too search for the file.

pushd C:
cd\
for /F "delims=" %%a IN ('dir /b /a-d /s chrome.exe') do (
  start "" "%%a" --kiosk --fullscreen --incognito "https://www.netflix.com/in/"
)
pause
Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • thanks for ur reply, hope u understand my question...i want to use that installed location in a variable and use that variable for my code instead of full manually typed path – learner Apr 20 '18 at 06:53
  • @learner copy the code in my answer, exactly, and paste into a file and name it `myfile.cmd` DO NOT change anything in the batchfile, save it and run it, then let me know what happens. – Gerhard Apr 20 '18 at 06:59
  • @learner Try now please.. you needed to remove echo, please read answers carefully. Anyway, copy the code again and try – Gerhard Apr 20 '18 at 07:02
  • in cmd window iam getting "INFO: Could not find files for the given pattern(s)." – learner Apr 20 '18 at 07:06
  • then there are issues with your installations. – Gerhard Apr 20 '18 at 07:08
  • already i am running my bat file and its working fine in my system..if there is any installation issue my bat also will not work ..right? – learner Apr 20 '18 at 07:09
  • No, what I am saying is that the installation does not place the paths in the environment, it works yes, but `where` will not find it. I will update my solution now. – Gerhard Apr 20 '18 at 07:10
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/169405/discussion-between-learner-and-gerhard-barnard). – learner Apr 20 '18 at 07:11
1

The simple solution is:

start "" chrome.exe --kiosk --fullscreen --incognito "website url"

It is necessary to specify an empty title with "" or command START interprets the first double quoted string as optional title string. Run in a command prompt window start /? for help on this command and its options.

The reason for starting successfully Chrome without full path and without its folder path being included in environment variable PATH is explained in answer on Where is START searching for executables?

chrome.exe is (usually) registered correct according to guidelines of Microsoft for Application Registration. So START is capable finding the path of Chrome application itself.

Solution with first checking if Chrome is installed and registered at all:

@echo off
%SystemRoot%\System32\reg.exe query "HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe" >nul 2>&1
if not errorlevel 1 start "" chrome.exe --kiosk --fullscreen --incognito "website url"
Mofi
  • 46,139
  • 17
  • 80
  • 143