我已经编写了一个简单的服务,该服务现在在Windows服务中处于活动状态。我的问题是我无法通过Windows服务访问cmd。我正在为我的服务使用nodejs express,为cmd访问使用node-cmd
并为服务创建node-windows
。我的应用程序执行此操作:
app.get('/check', (req, res) => {
cmd.run('start chrome');
res.status(200).send('The server is working correctly :)');
});
对于那些不了解这一点的人,基本上表示:
Listen for the GET '.../check' call, then do:
cmd: start chrome
return response 'The server is working correctly :)'
当我手动运行它时,它将启动chrome。当我将其用作Windows服务时,它不会启动chrome,但会与The server is working correctly :)
由于某些原因,cmd命令在Windows服务中不起作用?
答案 0 :(得分:1)
在Windows Vista服务中,服务进程在与用户进程不同的会话/桌面中运行(存在Microsoft white paper)。
因此,如果您从服务启动chrome.exe
,则它将在服务会话中运行,并且在用户的桌面上不可见。您可以检查任务列表以确保它已启动。