Node js start and stop windows services

感情迁移 提交于 2019-12-02 21:02:30

In windows, from a command line you can type:

# Start a service
net start <servicename>

# Stop a service
net stop <servicename>

# You can also pause and continue

So, the simple answer is - use child-process to start the service on startup of your server. Something like this:

var child = require('child_process').exec('net start <service>', function (error, stdout, stderr) {
    if (error !== null) {
        console.log('exec error: ' + error);
    }
    // Validate stdout / stderr to see if service is already running
    // perhaps.
});

EDIT: I also found this nodejs module called "windows-service". Seems promising for what you are attempting to do. Some of its functionality is implemented in C++ where it attempts to query the Windows Service Manager.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!