Detecting if a Windows process AND application is running

半城伤御伤魂 提交于 2019-12-12 16:40:27

问题


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?

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.

Any advice?


回答1:


check if a certain process is running as a process

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");

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");
  }
}


来源:https://stackoverflow.com/questions/13648304/detecting-if-a-windows-process-and-application-is-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!