gpt4 book ai didi

node.js - 使用 NodeJS 列出正在运行的应用程序

转载 作者:搜寻专家 更新时间:2023-10-31 23:38:10 25 4
gpt4 key购买 nike

我想使用 NodeJS 获取 Windows 上打开的应用程序列表。

类似的东西:

exec("tasklist", function (error, stdout, stderr) {

for(var i=0;i<stdout.length;i++)
{
if( stdout[i]['name'].indexOf('ll_') > -1 )
{
appList.push({'id':stdout[i]['id'],'name':stdout[i]['name']});
}
}

});

其中 appList 是运行应用程序的对象,如果应用程序以 ll_ 开头,则其 ID 和名称。

我该怎么做?

最佳答案

(我没有运行 Windows,所以以下内容未经测试)

首先,安装tasklist :

$ npm install tasklist

然后,使用以下脚本:

var tasklist = require('tasklist');

tasklist(function(err, tasks) {
if (err) throw err; // TODO: proper error handling
var appList = tasks.filter(function(task) {
return task.imageName.indexOf('ll_') === 0;
}).map(function(task) {
return {
id : task.pid, // XXX: is that the same as your `id`?
name : task.imageName,
};
});
});

关于node.js - 使用 NodeJS 列出正在运行的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30863751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com