Dynamically find Chrome on end-user's Windows machine

So, I have searched everywhere I can think of for this, and can't figure it out. I'm hoping the answer is very simple. Here is the situation:

I am creating a shortcut link for an end-user. We will call it "shortcut.lnk". We can assume that they do have Chrome installed and that "myFolder" is on their Desktop. The key is that this app needs to open up in Chrome, not the user's default browser. Currently, I have the following as the "Target" of shortcut.lnk:

%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe --app=%USERPROFILE%\Desktop\myFolder\path\to\app.html

This works on the 3 machines I have tested it on. However, I have noticed from research that Chrome sometimes installs in AppData or other locations instead of Program Files.

My question is this, is there a way to dynamically determine where Chrome is installed on their Windows machine in a way that I can attach it to the "Target" of shortcut.lnk?


Solution 1:

Is there a way to dynamically determine where Chrome is installed?

The following command will determine where chrome is installed and set the CHROMEPATH environment variable to this value:

for /f "usebackq tokens=1,2,3,4,5" %a in (`reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\ /s /f \chrome.exe ^| findstr Application`) do set CHROMEPATH=%c%d%e

Example output:

echo %CHROMEPATH%
C:\ProgramFiles(x86)\Google\Chrome\Application\chrome.exe

To use in a batch file you need to double up the percents as follows:

for /f "usebackq tokens=1,2,3,4,5" %%a in (`reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\ /s /f \chrome.exe ^| findstr Application`) do set CHROMEPATH=%%c%%d%%e