【问题标题】:cannot start service from the command line or a debugger. a windows service must first be installed Nodejs无法从命令行或调试器启动服务。必须先安装一个windows服务Nodejs
【发布时间】:2019-07-03 10:27:12
【问题描述】:

我正在创建一个 Windows 服务,它将一些数据随机添加到数据库中,所以我使用 node-windows 来实现它,当我运行该文件时,它会创建一个可执行文件,当我运行该文件时,我得到“无法启动服务从命令行或调试器。必须首先安装 Windows 服务“ 我该怎么办??

这里是 app.js 文件代码:

var Service = require('node-windows').Service;
var svc = new Service({
    name:'finaltest',
    description: 'The nodejs.org example web server.',
    script: 'testapp.js',

  });

  // Listen for the "install" event, which indicates the
  // process is available as a service.
  svc.on('install',function(){
    svc.start();
  });



  svc.install();

这是 testapp.js 文件代码:

var test = require('./models/test') ;
test.create({test : Math.random()}).then( () => {
    console.log('hey') ;
})
setInterval(function(){


    test.create({test : Math.random()}).then( () => {
        console.log('hey') ;
    })
}, 60000);

【问题讨论】:

    标签: node.js windows-services node-windows


    【解决方案1】:

    在运行 Windows 服务之前,必须先使用 installutil 将其“安装”。例如:

    C:\installutil -i c:\path\to\project\debug\service.exe
    

    使用 net stop [service name] 停止它并使用 net start [service name] 再次启动它,基本上是重新启动服务。

    如果是这样,你应该确保你做的事情正确。如果这不是您想要的,请更具体地说明您要做什么,并随时告诉我。

    首先你应该确保你的服务代码工作正常。

    其次,如果你是win7或win8操作系统,

    1. 在 Windows 开始菜单或开始屏幕上,选择 Visual Studio、Visual Studio 工具、开发人员命令提示符。
    2. 出现 Visual Studio 命令提示符。
    3. 从命令提示符运行 InstallUtil.exe,并将项目的输出作为参数:

      installutil /u "你的项目".exe

    这是我的截图,

    【讨论】:

    • 我得到:“'installutil' 未被识别为内部或外部命令??
    • 当我运行 installutil 命令时,我得到这个“在 C:\ ...\ nodeservicetest service.exe 程序集中找不到具有 RunInstallerAttribute.Yes 属性的公共安装程序。删除了 InstallState 文件,因为没有安装程序。”但最后它说安装已经完成,当我运行 net start 时,我被拒绝访问。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-06
    • 1970-01-01
    • 1970-01-01
    • 2018-10-26
    相关资源
    最近更新 更多