Trying to run sample batch file from php to close firefox browsers. but it doesnt close the browsers. manually if execute batch file from command prompt it is working.
closebrowsers.bat
tskill firefox
close.php
<?php
exec('cmd /c C:\wamp\www\fedex\closebrowsers.bat');
print "done";
?>
Tried with absolute path, without absolute path, escaping back slashes.
exec('cmd /c C:\\wamp\\www\\fedex\\closebrowsers.bat');
exec('cmd /c closebrowsers.bat');
As an alternative to tskill
you can use taskkill
<?php
print `C:\\Windows\\system32\\taskkill.exe /F /IM chrome.exe /T`;
// or event without the full path to the executable
// print `taskkill.exe /F /IM chrome.exe /T`;
// and even without the full executable name
// print `taskkill /F /IM chrome.exe /T`;
Will output something on the lines of
SUCCESS: The process with PID 16972 (child process of PID 17912) has been terminated.
SUCCESS: The process with PID 10200 (child process of PID 17912) has been terminated.
....
SUCCESS: The process with PID 16764 (child process of PID 17912) has been terminated.
SUCCESS: The process with PID 17912 (child process of PID 2760) has been terminated.
No need for a separate batch file.
/F - forcefully terminates a process
/IM - passes an image name, ex. chrome.exe
/T - kill child processes too
You can use exec
instead of the backtick operators.