node-windows
node-windows copied to clipboard
The very first time node-windows is used to install a service, it won't start.
I am using node-windows
to run a basic script to install and run a service. The very first time this script is executed, the service appears in the Windows services manager, but does not start, even though my on-start listener was triggered.
Every subsequent time I invoke this script on this device, the service starts normally. Strangely enough, I can remove all files, uninstall the service using node-windows
, even sc delete
the service, and after invoking the script, the service starts normally as well. I can even give the service a different name and description, and that service now starts normally too.
When I examine the daemon
folder, there are none of the log files I expect to see either until I invoke the start
operation again.
I am using the latest version of node
and node-windows
. I have seen this issue both on Windows 7 and Windows Server 2008.
I've seen this occur as well, on my fork of node-windows but could never figure it out. Would be nice if someone can solve it...
+1
Was someone able to solve this issue? I am getting similar issue.
I have used absolute path as value for my script property. So I guess I could rule out this issue mentioned here
@29leinad same here. It's not an important bug for me, I only needed to manually start the service once and everything works, but I am curious to what the solution is.
I have observed the same issue.
The problem seems to be related to the way node-windows is executing console commands. It is using "NET START"/"NET STOP" commands, but one of the following execution methods may be used depending on additional parameters:
- VB script "elevate" - this is used in most of the cases, when no additional params specified. The problem is: this does not wait for the end of the command execution, and it does not return the result properly (in case of any errors). It always returns "ok" immediately. I suspect it is causing problems when one calls multiple methods on the same service, one by one, or if the js scripts simply ends, which may happen before the console command finishes.
- "sudo" app, when "sudo.password" parameter is specified . I did not try this one.
- "exec" method from "child_process" module , when "user.account" and "user.password" parameters are specified. This is working properly , i.e. it waits for the command to finish, and returns the command return code properly. I have never seen these problems any more, once I started to use this very method. Unfortunately, there is another bug in here: account and password parameters are totally ignored (see the line 644 in daemon,js - "cmd" is used instead of "_cmd" ) so it works only if you are already "elevated" administrator.
I am afraid this part of "daemon,js" is to be reworked. Possibly also the VB script , which does not work as expected.
We are having the same issue, any workaround for cases without username & password? (we are deploying across different pcs, so we can't hard code username & password, and there is no reason to ask users to input it)
I am setting literally: user.account=’dummy’ ; user.password=’dummy’ , regardless on the real admin password. This works, because these values are totally ignored in node-windows. But, if they are set to any non-empty value, then the other execution path is taken internally (“exec” method instead of VB script).
Again, this is a very nasty workaround which can be used when the js script is called by “already elevated” administrator. Also, it would work as long as the "credential ignoring" defect is still in code, it will stop working once this is fixed in daemon.js
The real fix would require the rework of the way node-windows calls the shell commands.
@tokla thanks! Will use your method, until it gets fixed.
For other reading this post I can confim @tokla method works.
This also fixes issue #117 when uninstalling services produces this error:
fs.js:1089
return binding.unlink(pathModule._makeLong(path));
^
Error: EPERM: operation not permitted, unlink 'C:\Users\Me\AppData\Roaming\BackgroundProcess\activity\daemon\activity.exe'
at Error (native)
at Object.fs.unlinkSync (fs.js:1089:18)
at rm (C:\Users\Me\AppData\Roaming\npm\node_modules\node-windows\lib\daemon.js:481:22)
at C:\Users\Me\AppData\Roaming\npm\node_modules\node-windows\lib\daemon.js:494:15
at ChildProcess.exithandler (child_process.js:197:7)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:877:16)
at Socket.<anonymous> (internal/child_process.js:334:11)
at emitOne (events.js:96:13)