doulu8847 2012-11-30 15:36
浏览 956
已采纳

检测Windows进程和应用程序是否正在运行

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条回答 默认 最新

  • douxue4395 2012-11-30 16:15
    关注

    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]."
       Sending term signal!
    ";
        exec("taskkill /F /IM ".$out[1].".exe 2>NUL");
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!