taskkill from PHP exec

Abs picture Abs · Dec 5, 2009 · Viewed 9.3k times · Source

I have just tried to execute this:

function kill_hr(){

    exec("taskkill /IM uper.exe", $output = array(), $return);

    print_r($output);

    echo "<br />".$return;

}

However, the output is this and its not very useful:

Array ( ) 1

When the process doesn't exist its this:

Array ( ) 128

I am trying to work out why it gives me a 1 when the process exists - is this a permissions problem? If so, how can I rectify this?

Answer

Abs picture Abs · Dec 6, 2009

Thank you all for your help - I finally managed to kill the process using this:

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

I am sure it will work with exec as well, but the important part is the /F forcing it! :)