检测 Windows 进程和应用程序是否正在运行 [英] Detecting if a Windows process AND application is running

查看:75
本文介绍了检测 Windows 进程和应用程序是否正在运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究是否有办法以编程方式检查某个进程是否作为进程运行(在运行 exe 的列表中)AND 作为打开的应用程序(即在任务栏上)并根据结果采取行动.

I'm investigating if there is a way to programatically check if a certain process is running as a process (in the list of running exe's) AND as an open application (i.e on the taskbar) and take action based on the results.

另外 - 有没有办法以编程方式杀死进程正在运行的应用程序?

Also - is there a way to programatically kill a process OR a running application?

我们正在此服务器上运行 WAMP 应用程序,因此理想情况下,我想要一种使用 PHP 执行此操作的方法,但我愿意接受最有效的方法.

We are running a WAMP application on this server so ideally i'd like a way to do this using PHP, but am open to whatever will work best.

有什么建议吗?

推荐答案

检查某个进程是否作为进程运行

check if a certain process is running as a process

如果您有 tasklist 命令,请确保:

If you have the tasklist command, sure:

// show tasks, redirect errors to NUL (hide errors)
exec("tasklist 2>NUL", $task_list);

print_r($task_list);

然后你可以杀死它,通过从行中匹配/提取任务名称来使用.

Then you can kill it, using by matching/extracting the tasknames from the lines.

exec("taskkill /F /IM killme.exe 2>NUL");

我在 php-cli 中经常使用它.示例:

I used that a lot with php-cli. Example:

// kill tasks matching
$kill_pattern = '~(helpctr|jqs|javaw?|iexplore|acrord32)\.exe~i';

// get tasklist
$task_list = array();

exec("tasklist 2>NUL", $task_list);

foreach ($task_list AS $task_line)
{
  if (preg_match($kill_pattern, $task_line, $out))
  {
    echo "=> Detected: ".$out[1]."\n   Sending term signal!\n";
    exec("taskkill /F /IM ".$out[1].".exe 2>NUL");
  }
}

这篇关于检测 Windows 进程和应用程序是否正在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆