start program in php

98 views Asked by At

I want to have a site in PHP that is able to start and stop a program on my local machine. Until now, I was only able to shutdown the program, but i can't get it to start. It has to work on a extern machine (anywhere else then my network) as well. The site is hosted on Wamp server

My code is:

<?php
if (isset($_POST['shutdown'])) {
  $cmd = "taskkill /f /im euroscopefsdserver.exe /t";
  shell_exec($cmd);
}
if (isset($_POST['start'])) {
  shell_exec("E:\\Programma's\Euroscope\euroscopefsdserver");
}
if (isset($_POST['restart'])) {
  $cmd = "taskkill /f /im euroscopefsdserver.exe /t";
  $cmd2 = "E:\Programma's\Euroscope\EuroScopeFsdServer";
  shell_exec($cmd);
  shell_exec($cmd2);
}
 ?>


 <form action="index.php" method="post">
   <input type="submit" name="start" value="Start">
   <input type="submit" name="shutdown" value="Shutdown">
   <input type="submit" name="restart" value="Restart">
 </form>
1

There are 1 answers

3
Adeojo Emmanuel IMM On

To launch a program on the computer which runs the webserver:

 <?php
    exec('"C:\Program Files (x86)\Notepad++\notepad++.exe" "C:\foo.php"');
 ?>

or

 <?php
    $file= shell_exec("C:\Program Files (x86)\Notepad++\notepad++.exe");
    echo $file."</br>";
 ?>