2013-07-07 84 views
1

我正在運行Windows 7 64bit for WAMP 2服務器。taskkill windows命令提示符不會查殺所有進程php

我從batch script使用Windows Com Component爲前運行我的程序:

C:\wamp\bin\php\php5.3.13\php.exe C:\wamp\www\test\command.php 
$WshShell = new COM("WScript.Shell"); 
$oExec = $WshShell->Run($command, 7, false); 

現在,當我發現有多少"cmd.exe"程序正在運行,它列出了我使用以下命令的所有進程:

tasklist /svc /fi "imagename eq cmd.exe" 

然後我用下面的命令用php腳本殺死它們:

$output = shell_exec('taskkill /F /IM "cmd.exe"'); 

在這裏,發生的是,並非所有我的cmd.exe窗戶關閉。

上面的代碼中可能有什麼錯誤? Some windows are closed, while some remains open which is executing the command.

請幫忙。

+0

它確實對我有用。曾嘗試以管理員身份運行它? – HamZa

+0

是的,我以管理員身份運行。我看到很多其他帖子有相同的問題,但不知道什麼是確切的解決方案。 –

回答

1

找到了解決方法[雖然開放提供更好的建議]

首先需要check and kill如果php tasks exists,然後command prompt will kill

// It will first list out all `php.exe` tasks running 
$output = shell_exec('tasklist /svc /fi "imagename eq php.exe"'); 
print_r($output); 
echo "<br> ------------------------------------ <br>"; 

// It will first list out all `cmd.exe` tasks running 
$output = shell_exec('tasklist /svc /fi "imagename eq cmd.exe"'); 
print_r($output); 
echo "<br> ------------------------------------ <br>"; 

// kills php.exe tasks 
$php_output = shell_exec('taskkill /F /IM "php.exe"'); 
print_r($output); 
echo "<br> ------------------------------------ <br>"; 

// kills cmd.exe tasks 
$cmd_output = shell_exec('taskkill /F /IM "cmd.exe"'); 
print_r($output); 
echo "<br> ------------------------------------ <br>"; 

die(ucfirst('all tasks killed')); 

希望它可以幫助大家!

相關問題