coreybutler / node-windows

Windows support for Node.JS scripts (daemons, eventlog, UAC, etc).
Other
2.8k stars 356 forks source link

how to map a Service to the corresponding process in the process wincmd.list ? #171

Closed DrYSG closed 4 years ago

DrYSG commented 7 years ago

@coreybutler , on Windows-10, I have created an installer for a node.js app. The install process is as follow:

var watsonApp = path.join(__dirname, "..", "..", "watson", "app.js");
var svc = new Service({
    name: 'EGPL Watson Service',
    description: 'The EGPL GeoLibrarian Watson Web Service',
    script: watsonApp,
    env: {
        name: "NODE_ENV",
        value: process.env["NODE_ENV"]
    }
});

The issue I now have is that I am trying to walk the process list that I get from wincmd.list to match the stats of the process with this service. I can do this manually if I know the PID, but the values returned for that process, are bascially useless to see if this is really the Node.js service. (ie. there can be a lot of node.exe images running on the system, so it is only that I know the PID, that this works. But I have no idea how to find the PID from the SVC?

{ ImageName: 'node.exe',
  PID: '16964',
  SessionName: 'Services',
  'Session#': '0',
  MemUsage: '17,960 K',
  Status: 'Unknown',
  UserName: 'N/A',
  CPUTime: '0:00:00',
  WindowTitle: 'N/A' }

What I am seeing is that there are actually three processes created, that are grand-child, child, and parent, with the parent process being the ImageName: 'egplwatsonservice.exe', So yes, I can find that process, but it is the grandparent of the process I want.

A picture is worth a 1,000 words, so here is what I am seeing"

capture

coreybutler commented 6 years ago

I'm sorry this slipped through the cracks. I assume you've found an answer or abandoned the effort by now?

There is currently no way to retrieve the specific PID from a created service. I'd accept a PR making this possible.