How to add a button that runs an application with php?

Question:

How do I create a button to run an application on my server through php? What I want is through a web page I can run a script or application (*.vbs, *.exe ) on my server.

Answer:

There are several ways to run a program through php. However, if the server is not enabled, not the entire program will be able to run.

Option 1Using exec()

With this command it will run the program and return the last line of the result.

$retorno = exec('wscript "dir/arquivo.vbs"');

Option 2Using COM

Using COM can be interesting if you are going to run windows programs. He's fit for it. You can run programs in word for example.

$obj = new COM ( 'WScript.Shell' );
$obj->Run ( 'cmd /C ' . "wscript.exe dir/arquivo.vbs", 0, FALSE );

Option 3Using shell_exec

shell_exec is very similar to exec , but it will execute a program via the shell and return all its output.

$retorno = shell_exec (start wscript "dir/arquivo.vbs");

Option 4Using the system

It is also similar to exec , but it returns the result on the screen to the user if a variable is not assigned to the command.

system("dir/arquivo.vbs");
Scroll to Top