coreybutler/node-windows

Can't get running as specific user to work

drone1 opened this issue · 18 comments

The documentation says this:

By default, it will run using the user account that launched the process (i.e. who launched node app.js).

However, if I put this in app.js:

var username = process.env['USERPROFILE'].split( path.sep )[2];

And log it, I get 'system32' rather than my username.

If I put that same printout in the appservice.js file (which creates the Service object, etc), it prints the username I would expect, which is my username.

I've tried explicitly overriding the Service instance's user object with my credentials and domain name, but that doesn't help either. I get 'system32' in that case as well.

Anyone know if this is a bug, or if I'm doing something wrong?

Thanks in advance!

You're probably better off looking for the last element in the path than hardcoding the 3rd element:

var username = process.env.USERPROFILE.split(path.sep).pop();

The code above will split the string and return the last "directory", which should match up with the username.

OK, thanks for that.

So now the username prints out as "systemprofile" rather than "system32" from app.js even if I specify my domain/username/password via the Service's user object in my service.js file. So, service.js prints out my username, but app.js prints out systemprofile, with or without me explicitly setting a domain/user/password.

Any idea what I need to do to get app.js to run as my user? Thanks a bunch.

Hi, any update on this corey? If you follow my repro steps, can you get app.js to run as a specific user? Any help would be much appreciated, as this will make a feature I've been working on a lot more useful.

If you open the windows services, right click on the service name, and look at the properties, which user account is the script setup to run as?

So I finally figured this part out and it was NOT set to my username. It was the default/system user.

On Mon, May 25, 2015 at 11:55 AM, Corey Butler notifications@github.com
wrote:

If you open the windows services, right click on the service name, and look at the properties, which user account is the script setup to run as?

Reply to this email directly or view it on GitHub:
#89 (comment)

That's what I was guessing... glad you figured it out!

But setting the username in the node-windows settings doesn't work, because even with my credentials and domain, it installs the service as the system user. So there still may be a bug here.

On Mon, May 25, 2015 at 5:09 PM, Corey Butler notifications@github.com
wrote:

That's what I was guessing... glad you figured it out!

Reply to this email directly or view it on GitHub:
#89 (comment)

@doArcanjo - I don't really know... node-windows only supports versions of Windows that haven't reached EOL. I haven't (nor intend to) looked at intricacies of supporting anything prior to Windows 7.

This is 7.

On Tue, May 26, 2015 at 4:07 PM, Corey Butler notifications@github.com
wrote:

I don't really know... node-windows only supports versions of Windows that haven't reached EOL. I haven't (nor intend to) looked at intricacies of supporting anything prior to Windows 7.

Reply to this email directly or view it on GitHub:
#89 (comment)

7 and 8, and 8.1 not xp althought

Wat

On Wed, May 27, 2015 at 7:33 AM, doArcanjo notifications@github.com
wrote:

7 and 8, and 8.1 not xp althought

Reply to this email directly or view it on GitHub:
#89 (comment)

I was just commenting on @doArcanjo's post on the article, which is referencing Vista.

griff commented

winsw has an option in the XML called serviceaccount which it looks like node-windows isn't setting.

@griff I'm actually running into this issue right now, and I tried to modify the code to add the option. However, the service still starts running as local system. Would you happen to have any thoughts?

@liu-jianyang It's not possible to change the owner of the service process (which is managed in Services management console) inside javascript code. The idea behind svc.user options is to configure the account that runs node app wrapped inside the windows service. Does that help?

Ah ok, that helps, thanks. So there is no way to change the owner via javascript?

Oh! You mean at the time of windows service installation! There must be a cmd line script switch (install
script just wraps a windows tool), but I wouldn't know. Anyone?