When run on a command prompt script runs with local user permission.
The same script when run from a browser runs as user IUSR_<<computer_name>>. This user being a guest account user doesnot have permission to work with processes.
Try giving IUSR account full permissions. This is the scenario with IIS.
I hope a similar thing exists with Apache. Give it a try.