2

I use this plugin to create a windows service: https://github.com/coreybutler/node-windows. I want to start an external program with my service. EDIT 1:

var cp = require("child_process");
cp.exec("C:\\Users\\test\\Desktop\\file.exe", function(error, stdout) {
}); 

Subsequently i try with a method of plugin. EDIT2

node_windows.elevate("C:\\Users\\test\\Desktop\\file.exe",function(error,stdout){
 });

This method start exe but i don't see GUI in Desktop. If i check option in services.msc => Interact with desktop i see another windows that ask me to confirm interaction of program, like this: http://help.tcadmin.com/images/d/dd/InteractWithDesktop.png If i choose "VIEW THE MESSAGE" it redirect me to another section, that have only my program and node bash without desktop's app (LIKE THIS: https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/4029645611/original/7daystodie-session0.png?1471375419)

I have already open an issue: https://github.com/coreybutler/node-windows/issues/163

Anyone can help me?

Mr.Orange
  • 426
  • 1
  • 4
  • 8

1 Answers1

0

As noted in the Github issue, this is probably a permissions issue.

The most granular way to run a child process while explicitly defining the user context is to run the cmd.exe. So, it might look something like the following (untested) pseudo code:

require('child_process').exec('cmd.exe', ['/c /env /user:username C:\nodejs\node.exe C:\path\to\myscript.js'], function(){...})

You can read more about cmd and runas on technet.

This approach comes with a whole bunch of caveats (which is why I recommend avoiding it). It makes your code platform-specific (i.e. node-mac and node-linux won't work with this). I've also noticed nuances with runas on different versions of Windows, and it can be tough to nail down issues.

Corey
  • 5,133
  • 3
  • 23
  • 24
  • I have same problem and it's not working also if I run process and child process with Administrator and full permissios!!! As @Mr.Orange said I think it's a problem of Windows service. I see that process also go in background processo for Windows 10 !! – Davide Mar 03 '17 at 15:57
  • @Davide - remember that it administrative permissions are not always enough. There are several situations where Windows requires ELEVATED administrative permissions. – Corey Mar 03 '17 at 16:00
  • The issue is that the `exe` start fine!!! But it goes in background mode and it not show GUI But for the service the program it's started and it's true!! We have tried with many different exe to start but nothing change. – Davide Mar 03 '17 at 16:06
  • @Davide - In that case, the exe would need to focus itself. The only way to do that is to write that code in the exe itself. If you don't have the source code for it, you're probably out of luck. My only other suggestion is to consider using a child_process.spawn instead of child_process.exec. Spawn allows you to detach the process, which might make a difference to the exe. – Corey Mar 03 '17 at 17:23