alumwell
asked on
Using exec in PHP to run program?
Hello.
I'm trying to make use of the exec feature in PHP. I'm trying to run the following command:
C:\psshutdown.exe @c:\shutdown.txt -u administrator -p password -t 60 -f -k -c -m "This PC Will Blow Up In 60 Seconds! Run You Fool!?"
The above command works prefectly in the command line, so i put together the code in the code snippet, although when i run it, it just 'thinks' for about 10 seconds then finishes, but the command isn't working. There is nothing output from '$output' and if i print '$return_var' it shows '-1073741502'.
i tried running a process manager to see what it was running and got these results:
http://img148.imageshack.us/my.php?image=ssinternalsuh7.jpg
It appears to show that it's run it, but it hasn't. I've noticed that it closed cmd very quickly after the command was run, perhaps not being it enough time to run?
Anyone have any suggestions why it's not working?
Thanks.
I'm trying to make use of the exec feature in PHP. I'm trying to run the following command:
C:\psshutdown.exe @c:\shutdown.txt -u administrator -p password -t 60 -f -k -c -m "This PC Will Blow Up In 60 Seconds! Run You Fool!?"
The above command works prefectly in the command line, so i put together the code in the code snippet, although when i run it, it just 'thinks' for about 10 seconds then finishes, but the command isn't working. There is nothing output from '$output' and if i print '$return_var' it shows '-1073741502'.
i tried running a process manager to see what it was running and got these results:
http://img148.imageshack.us/my.php?image=ssinternalsuh7.jpg
It appears to show that it's run it, but it hasn't. I've noticed that it closed cmd very quickly after the command was run, perhaps not being it enough time to run?
Anyone have any suggestions why it's not working?
Thanks.
<?php
$output = array();
$return_var = 0;
$command='C:\psshutdown.exe @c:\shutdown.txt -u administrator -p password -t 60 -f -k -c -m "This PC Will Blow Up In 60 Seconds! Run You Fool!?"';
exec($command, $output, $return_var);
sleep(10);
exec("exit(0)");
foreach($output as $outputline){
echo("$outputline<br>");
}
?>
ASKER
Thanks for your reply.
Just tried the code you gave me, unfortunatly it waits the time but the command isn't being run and it doesn't display anything once it's finished.
Any other ideas?
thanks again.
Just tried the code you gave me, unfortunatly it waits the time but the command isn't being run and it doesn't display anything once it's finished.
Any other ideas?
thanks again.
Does this give you an error you can read?
<?php
ignore_user_abort ();
set_time_limit (0);
$command='C:\psshutdown.exe @c:\shutdown.txt -u administrator -p password -t 60 -f -k -c -m "This PC Will Blow Up In 60 Seconds! Run You Fool!?"';
echo shell_exec($command . ' 2>&1');
?>
ASKER
Nope. Nothing. Any ideas?
Thanks.
Thanks.
I have only one more idea.
Create a batch file called "psshut.bat" and put it here:
C:\psshut.bat
The batch file should contain one line only:
C:\psshutdown.exe @c:\shutdown.txt -u administrator -p password -t 60 -f -k -c -m "This PC Will Blow Up In 60 Seconds! Run You Fool!?"
Then exicute the batch file from PHP:
<?php
$command='C:\psshut.bat';
echo shell_exec($command . ' 2>&1');
?>
If that does not work, I cannot help.
What you are trying to do could be considered dangerous from a security standpoint. It is possible that a firewall or some other security software is preventing you from doing this. Beyond that, I am sorry, without a specific error message I am shooting in the dark.
Create a batch file called "psshut.bat" and put it here:
C:\psshut.bat
The batch file should contain one line only:
C:\psshutdown.exe @c:\shutdown.txt -u administrator -p password -t 60 -f -k -c -m "This PC Will Blow Up In 60 Seconds! Run You Fool!?"
Then exicute the batch file from PHP:
<?php
$command='C:\psshut.bat';
echo shell_exec($command . ' 2>&1');
?>
If that does not work, I cannot help.
What you are trying to do could be considered dangerous from a security standpoint. It is possible that a firewall or some other security software is preventing you from doing this. Beyond that, I am sorry, without a specific error message I am shooting in the dark.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also, you are sleeping for only 10 seconds, and I think you will need to sleep fore more than 60.
Open in new window