node-windows icon indicating copy to clipboard operation
node-windows copied to clipboard

Can't get running as specific user to work

Open drone1 opened this issue 10 years ago • 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!

drone1 avatar May 13 '15 02:05 drone1

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.

coreybutler avatar May 13 '15 18:05 coreybutler

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.

drone1 avatar May 13 '15 19:05 drone1

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.

drone1 avatar May 18 '15 19:05 drone1

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?

coreybutler avatar May 25 '15 15:05 coreybutler

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 [email protected] 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: https://github.com/coreybutler/node-windows/issues/89#issuecomment-105255931

drone1 avatar May 25 '15 20:05 drone1

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

coreybutler avatar May 25 '15 21:05 coreybutler

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 [email protected] wrote:

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

Reply to this email directly or view it on GitHub: https://github.com/coreybutler/node-windows/issues/89#issuecomment-105314390

drone1 avatar May 25 '15 23:05 drone1

mmm... Is possible to do this? http://www.codeproject.com/Articles/35773/Subverting-Vista-UAC-in-Both-and-bit-Archite

doArcanjo avatar May 26 '15 04:05 doArcanjo

@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.

coreybutler avatar May 26 '15 20:05 coreybutler

This is 7.

On Tue, May 26, 2015 at 4:07 PM, Corey Butler [email protected] 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: https://github.com/coreybutler/node-windows/issues/89#issuecomment-105650624

drone1 avatar May 26 '15 20:05 drone1

7 and 8, and 8.1 not xp althought

doArcanjo avatar May 27 '15 14:05 doArcanjo

Wat

On Wed, May 27, 2015 at 7:33 AM, doArcanjo [email protected] wrote:

7 and 8, and 8.1 not xp althought

Reply to this email directly or view it on GitHub: https://github.com/coreybutler/node-windows/issues/89#issuecomment-105932762

drone1 avatar May 27 '15 21:05 drone1

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

coreybutler avatar May 27 '15 22:05 coreybutler

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

griff avatar Jun 15 '15 15:06 griff

@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 avatar Feb 04 '16 02:02 liu-jianyang

@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?

tishma avatar Feb 11 '16 13:02 tishma

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

liu-jianyang avatar Feb 12 '16 23:02 liu-jianyang

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?

tishma avatar Feb 17 '16 09:02 tishma