UNPKG

gpii-windows

Version:

Components of the GPII personalization infrastructure for use on Microsoft's "Windows" ™

83 lines (68 loc) 2.84 kB
/*! GPII Process Reporter processes bridge -- gpii.processes. Copyright 2016-2017 Inclusive Design Research Centre, OCAD University Licensed under the New BSD license. You may not use this file except in compliance with this License. You may obtain a copy of the License at https://github.com/gpii/universal/LICENSE.txt */ /*global require */ "use strict"; var path = require("path"), // This conditional require is to run the electron version of edge.js // when this code runs on electron (gpii-app). edge = process.versions.electron ? require("electron-edge-js") : require("edge-js"), stringArgv = require("string-argv"), fluid = require("gpii-universal"); var gpii = fluid.registerNamespace("gpii"); var dotNetProcesses = edge.func({ source: path.join(__dirname, "dotNetProcesses.csx"), references: ["System.Management.dll"] }); fluid.defaults("gpii.processes.windows", { gradeNames: ["gpii.processes"], invokers: { getProcessList: { funcName: "gpii.processes.windows.getProcessList", args: ["{arguments}.0"] // process name or id, optional. }, getProcessPath: { funcName: "gpii.processes.windows.getProcessPath", args: ["{arguments}.0"] // command name (string) } }, ignoreCase: true }); /** * Return the path of a running process. * * If the full path is not known (the process is running as another user), only the command is returned. * * @param {Component} that - an instance of a processes component. * @param {Number} pid - the process id of the process. * @return {String} - The full path of the process, or null if there's no matching process. */ gpii.processes.windows.getProcessPath = function (that, pid) { return gpii.windows.getProcessPath(pid); }; /** * Return a list of processes -- a snapshot of the current processes. If the * process name or process id is passed, then the return value will be limited * to only processes with that name or the process with that pid. * * @param {String|Number} processIdentifier [optional] Specify a process to find via a name, or a process id. * @return {Array<Object>} Array of processes. */ gpii.processes.windows.getProcessList = function (processIdentifier) { var procInfos = dotNetProcesses(processIdentifier, true); // Loop to convert the command line to an argv[]. fluid.each(procInfos, function (aProcInfo) { aProcInfo.argv = stringArgv(aProcInfo.commandLine); delete aProcInfo.commandLine; // In some cases the first argument is just the command, e.g., "Notepad". // In others, it is the full path and may include the ".exe" // extension. Normalize it to always be the full path. aProcInfo.argv[0] = aProcInfo.fullPath; }); return procInfos; };