I have a windows 7 Pro computer that is running XAMPP (apache, php).
What I need to do is execute a batch or powershell command on this computer (host) when a remote computer accesses a certain webpage on it. is this possible?
Yes, there is a PHP function that will execute shell code.
Have a look in their documentation
Function: exec("command here");
Related
I have an IIS server with Php and have been trying to execute scripts using exec() and system() with no luck. When i go to the machine and run it by double clicking it, or by opening command and running the batch file, 4 windows pop open with ffmpeg streams going and dump to folder.
With exec("cmd.exe 'c:\inetpub\wwwroot\estf\batch\srRecord.bat'");
I am getting some of the batch file process working (creates new folder and dumps to file, but i can't see the cmd gui anywhere. And my stop.bat won't taskkill the ffmpeg process.
Is there a way to bring up the cmd GUI on the external device, also a way to run the exec() command and pass on so that other devices or batch files can kill these tasks (i am thinking that because the php is still running it, nothing else has rights to stop it.
Regards,
Mitchell
I have a PHP script that runs one command. The command needs to be runned as administrator. If I run Windows console as administrator and execute the command it works perfectly, on the other hand if I run the script from Windows console as administrator using PHP console it works perfectly.
However if I run the PHP script using Apache server on my PC, my page never finish loading and it does not executes the command in rigth way. I have Apache running as a service and I change the user of Apache to administrator.
Do someone sees a problem with the way I´m doing things?
I am trying to call a python script from a php script. When I run the PHP script in the linux command prompt, the python gets executed properly. But when I run the php script on the web server, the python script isn't executed. Can anyone tell me why this is so and what I can do to correct it?
You can run it from linux command,because the system has python interpret.
So I think you should check whether the server support interpret python.
(i.e.some server may support asp instead of php for same reason)
hi I have a raspberry pi and install apache on this. On my raspberry runs raspian and I want to execute linux prompts about my web. For example I have a webapplication run on this apache and I want to shutdown the raspberry by a click on a button "shutdown". (This is only one method for my application). I build webapplications in php or C# with .NET.
Can I do this and what i must know for this?
I want to build a simple Webapplication for other users.
You can use exec(), system() or passthru() function to execute commands.
For example you can shutdown a linux system with:
<?php
exec("shutdown -h now");
?>
Make sure the apache user has the permission to execute this command.
I'm trying to run notepad on the server (localhost for now).
exec() and system() functions are working fine when for example write ping 127.0.0.1.
But this does not work (working fine if I write the command directly in the command prompt):
$command = "C:\WINDOWS\system32\notepad.exe";
$result = system($command);
print_r($result);
Using Windows XP with xampp. Probably I don't have permissions because the command is executed from some other account but I don't know how to check this.
Any advices?
Edit:
As bwoebi said, I have opened processes but they are opened from a different user (SYSTEM) and I can't see when the application is opened. So, I have to paraphrase my question: how to change the user which is used when executing commands from a PHP script?
First you need to escape the backslashes in your command string if you're not using single quotes :
$command = "C:\\WINDOWS\\system32\\notepad.exe";
Also note that if Apache is running as a Windows service, it does not have desktop interaction permission, so it can't open a GUI, try running the script directly with PHP on the command line.
EDIT
The user used to run command is the user that is running PHP. To change the user running PHP, you'll have to change the user running Apache, if you want this user to have desktop interaction permission, you'll have to run Apache yourself and not as a service.
let the process a bit sleep after executing the shell command and search in the TaskManager for a Notepad... Then you'll see that this are two different users (and you don't see the other users Notepad)
Note pad is a GUI program so requires the windows TTY to be active.
Ping is command line so can be ran by the system directly and piped results into the program calling it.
With out getting into too much detail of how os's work basically it can't be done on a windows machine (its possible on unix machines but more difficult.)