无法在Windows上启动本机消息传递主机,未设置"COMSPEC". [英] Failed to start native messaging host on Windows, "COMSPEC is not set"
问题描述
我有一个chrome扩展程序,可以与本机消息传递主机进行通信以获取一些数据.
I have a chrome extension that communicates with a native messaging host to get some data.
问题是,当我通过快捷方式或任务栏中的固定快捷方式启动Chrome浏览器时,扩展程序无法连接到主机.我总是会收到错误:
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.
但是,如果我通过命令提示符启动chrome.exe
,则一切正常.
However, if I launch the chrome.exe
via command prompt, everything works fine.
我尝试过的事没有成功:
Things I tried with no success:
- 任务栏快捷方式没有多余的标志.目标字段具有
以下值:
"C:\Program Files(x86)\Google\Chrome\Application\chrome.exe"
- 我尝试使用
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Google\Chrome\NativeMessagingHosts\com.company.extension
下的注册表
- 我尝试使用
HKEY_LOCAL_MACHINE\SOFTWARE\Google\Chrome\NativeMessagingHosts\com.company.extension
下的注册表
- 我尝试使用下面的注册表项
HKEY_CURRENT_USER\Software\Google\Chrome\NativeMessagingHosts\com.company.extension
- 试图以管理员身份从文件资源管理器中启动
chrome.exe
.
- 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
chrome.exe
as administrator from the file explorer.
更新:
我将标志--enable-logging --v=1
添加到了启用日志记录的快捷方式中,当我启动它时,我在控制台中得到以下输出:
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
更新
通过Process Monitor调查chrome.exe
进程时,我发现通过explorer
生成COMSPEC
环境变量时,没有可用的环境变量.
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 to cmd
, is unset:
[11036:4160:0302/113902.866:ERROR:native_process_launcher_win.cc(140)] COMSPEC is not set
从cmd
本身启动Chrome的行为有所不同,因为它会自行设置变量(生成的进程).
The behavior is different for launching Chrome from cmd
itself, since it sets the variable for itself (ans spawned processes).
这可以通过使用 Process Explorer .
一个人可以以admin(例如从admin命令行)运行rundll32 sysdm.cpl,EditEnvironmentVariables
以打开环境变量设置.
或者,可以从控制面板">系统和安全性">系统">高级系统设置">高级">环境变量..."中导航对话框.
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
通常在系统变量中设置为
ComSpec
is usually set in System variables to
C:\WINDOWS\system32\cmd.exe
根据需要进行调整,以进行系统安装.要应用此设置,您需要注销然后重新登录,或者最好重新启动系统.
Adjust 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.
这篇关于无法在Windows上启动本机消息传递主机,未设置"COMSPEC".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!