Search code examples
node.jselectronnode-windows

node-windows permission Denied - and not requesting rights after compiling?


I am trying to install dynamically windows services from my electron app.
For that i am using the node module "node-windows".

This looks like this:

service = new Service({
    name: 'Watcher',
    description: 'Watcher',
    script: 'Watcher.js',
    env: {
        name: "SettingsPath",
        value: storage.getDataPath()
    }
});

service.on('install',function(){
    service.start();
});

service.install();

this works very well on my dev machine.
The app requests for permission to create the service and installs it smoothly.

My Problem
If i compile the app to an exe the app doesnt request me for permissions and print an error

Permission Denied. Requires administrative privileges.

The app creates the service exe successfully at that time and doesnt do anything more.

Ok, so i started the app with admin privileges for testing this behavior.
Nice, the app doesnt show any error, creates the service exe AND ahhhhhh installed the service NOT.

Questions
Why does the app no ​​longer ask for permissions when it is compiled?
Why isn't the service installed when the app is compiled?

If you need any additional information, write me a comment. And thanks for your time.


Solution

  • the path to the elevate.cmd in node-windows is incorrect for electron apps.
    i have documented the way of trouble here

    found some more problems to use the node-windows package:

    • cant use scripts from electron asar file (exclude files or diable asar)
    • the executable path from the generated service config is wrong (its the packaged app executable, but must be node.exe or an equivalent executable)
    • service will only run on target system if node.js is installed, or you provide an equivalent