How can I invoke Chrome with a command line option when a hyperlink is clicked in an email?

2

I have a web application that requires the use of a Chrome command line option to run successfully. My users will be receiving emails with hyperlinks to invoke the web application in Chrome on their PCs. How can I invoke Chrome with a command line option when a hyperlink is clicked in an email? Obviously I will have to make Chrome the default browser on each user's PC but I do not know how to ensure that every invocation of Chrome includes that command line option.

jlavallet

Posted 2017-08-11T20:26:08.437

Reputation: 121

Try chrome "https://msn.com" or START "" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "https://msn.com" as a starting point. Replace msn.com with the URL of your choice though. You won't need to set Chrome as the default web browser if you use it's full explicit path and then pass it the URL you need it to open by the way. – Pimp Juice IT – 2017-08-11T20:33:00.613

So you are suggesting that the href I use in my anchor tag when I send the email would look like your example? – jlavallet – 2017-08-11T20:35:58.413

I know how to invoke Chrome from the command line (including my command line option which happens to be --explicitly-allowed-ports=8734) but I do not believe I can embed all that you just suggested in the HREF of my anchor tag. – jlavallet – 2017-08-11T20:38:46.023

Is the Hyperlink dynamic or static? I mean if it is always a static link that points to a URL (that never changes) - send them a pre-made shortcut or .lnk file. And the shortcut target could be something like "%PROGRAMFILES(x86)%\Google\Chrome\Application\chrome.exe" --explicitly-allowed-ports=8734 https://myapp.domain.com. I'm not sure if you can attach a .lnk file (your mail server may quarantine them) but you definitely can copy and paste .lnk files between computers. If it is a constantly changing URL... I guess you can keep making new .lnk file and share the new one? – Darius – 2017-08-11T20:49:40.480

Good call on using the environment variable so file:///%PROGRAMFILES(x86)%\Google\Chrome\Application\chrome.exe but I'm not sure about passing the arguments and URL to the site but have a look at https://stackoverflow.com/questions/2140585/pass-arguments-when-using-the-file-protocol as it may or may not be possible. There may be a workaround but I'm not 100% certain but maybe this will give others ideas to help give you a great answer that will suffice.

– Pimp Juice IT – 2017-08-11T23:27:30.997

Another idea would be to have a batch script on all the machines in a standard folder or a UNC file share where it can be read and executed by the users that click on the link and the batch file would have the START "" "%PROGRAMFILES(x86)%\Google\Chrome\Application\chrome.exe" --explicitly-allowed-ports=8734 https://myapp.domain.com logic in it just as I (and Darius) mentioned above, and the hyperlink could point to the batch so once clicked it executes the batch with the logic needed to tell Windows and Chrome to do its thing file:///\\server\share\folder\batchfile.cmd – Pimp Juice IT – 2017-08-11T23:33:29.583

If you use the UNC share and path for the batch script, you'd only need to maintain the one batch script, you could make changes to it in one place if changes are needed with the URL, parameters, etc. and the URL HREF link you send never changes and all users would have read-only and execute access to the batch script so they would not be able to modify it themselves. Maybe a simple solution for you but otherwise you could have the batch script on all local machines in the same one folder on all e.g. C:\Scripts but you'd need to update on for a simple changes with that method. Quick ideas. – Pimp Juice IT – 2017-08-11T23:36:56.020

Answers

0

1) If you have administrative access to user's registry, you can modify following key:

HKEY_CLASSES_ROOT\ChromeHTML\shell\open\command

For example

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"--incognito -- "%1"

This will works for all hyperlinks (including emails).

2) Also you can try remote parameters injection

<a href='chromehtml:www.google.com"%20--incognito"%20--"'>click me</a>

But this is a security vulnerability and it works only in old version of browsers (IE 8 and earlier).

matrix

Posted 2017-08-11T20:26:08.437

Reputation: 194