I have a chrome extension that communicates with a native messaging host to get some data.
The issue is, when I launch the Chrome browser via the shortcut or via the pinned shortcut in the taskbar, the extension is not able to connect to the host. I always get the error:
Failed to start native messaging host.
However, if I launch the chrome.exe
via command prompt, everything works fine.
Things I tried with no success:
- The taskbar shortcut has no extra flags. The target field has the
following value:
"C:\Program Files(x86)\Google\Chrome\Application\chrome.exe"
- I tried with the registry under
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Google\Chrome\NativeMessagingHosts\com.company.extension
- I tried with the registry under
HKEY_LOCAL_MACHINE\SOFTWARE\Google\Chrome\NativeMessagingHosts\com.company.extension
- I tried with the registry entry under
HKEY_CURRENT_USER\Software\Google\Chrome\NativeMessagingHosts\com.company.extension
- Tried launching the
crome.exe
as administrator from the file explorer.
Update:
I added the flag --enable-logging --v=1
to the shortcut to enable logging and when I launch it I get the following output in the console:
[11036:4160:0302/113902.866:ERROR:native_process_launcher_win.cc(140)] COMSPEC is not set
[11036:11856:0302/113902.882:ERROR:native_process_launcher_win.cc(140)] COMSPEC is not set
Update
Upon investigating the chrome.exe
process via Process Monitor, I found that there is no COMSPEC
environment variable available to it when it is spawned via explorer
.
Is there anything else that I can try or something that I am missing here?
As mentioned in the log, Chrome stumbles to start an external process, since
COMSPEC
, an environment variable pointing normally tocmd
, is unset:The behavior is different for launching Chrome from
cmd
itself, since it sets the variable for itself (ans spawned processes).This can be confirmed by inspecting the Chrome process with Process Explorer.
One can run
rundll32 sysdm.cpl,EditEnvironmentVariables
as admin (e.g. from admin command line) to open the environment variable settings.Alternatively, the dialog can be navigated to from Control Panel > System and Security > System > Advanced system settings > Advanced > Environment Variables...
ComSpec
is usually set in System variables toAdjust as necessary for your system install. For this setting to apply, you need to log out and log back in, or better yet restart the system.