1

I know this might be a very general question but what I am trying to do is initiate a .exe program from a php webapp.

The first screen of the .exe is a log-in form with username and password. I want to make the php code open the .exe program and insert the respective values for username and password into their fields (these values are stored in from mysql).

As i don't have the software that needs to be opened so far, I know that this may seem a vague question but I am looking for a general way or some pointers of doing this.

  • This is indeed a vague question, but care to be more specific? `system`, `exec`, ` `` /*backticks*/`, and `proc_open` are all candidates... is the `exe` a GUI application, or a cmd app? is it accessible, and does it run on the same server as your script does? check [this question](http://stackoverflow.com/questions/10102952/proc-open-interaction), and [this question](http://stackoverflow.com/questions/9843550/load-profile-with-proc-open), both are mine, asked about a year ago, but still apply – Elias Van Ootegem Jul 03 '13 at 07:40
  • Ok, so [the first linked question](http://stackoverflow.com/questions/10102952/proc-open-interaction) still applies, if it's a non-GUI app, you should be able to take it from there. – Elias Van Ootegem Jul 03 '13 at 07:48
  • the webapp will be hosted on an external server but the .exe will run on a pc. The .exe will run on a windows pc and will have a predetermined path something like "c:\Program files\soft\theexe.exe". The php script has this path and needs to open the .exe on the pc it is used to initiate the command. – Cristian Bican Jul 03 '13 at 07:53
  • Yes, I got all that, but if the php script needn't interact with the exe, then, using the lib in my linked question just `$ssh->exec('C:\\Path\\To\\app.exe');` would do. – Elias Van Ootegem Jul 03 '13 at 08:00
  • thanks, that clears the first part but any way of transferring some variables to that software for the login? or this will depend entirely on the structure that the software has/ platform it was built on? – Cristian Bican Jul 03 '13 at 08:05
  • Check my answer, you're pretty well catered for when it comes to passing arguments to the exe, or using a specific user to run that application, or logging on to the remote server/machine running the program. You'll have to try a few things, of course, with which I wish you the best of luck. – Elias Van Ootegem Jul 03 '13 at 08:21

1 Answers1

0

So, in light of the comment/chat we had under your question, using phpseclib, you should be able to connect to the remote machine, which will run your the application:

require_once('Net/SSH2.php');
$ssh = new Net_SSH2('winhostaddress');
//if needed:
if (!$ssh->login('user', 'pass'))
{
    exit('Failed to connect to win');
}
$ssh->exec('C:\\Path\\to\\app.exe argument1 argument2 argument3');

That should do the trick. When using flags, like on *NIX systems: ls -a, you should know that the Windows counterpart is /. Other than that, it's all pretty much the same. escapeshellarg is not to be forgotten, when passing client-data to the executable.

Arguments containing spaces should be delimited using double quotes.
If you're not sure weather or not the application you're launching is accessible to the user you used to connect via ssh, try prepending this to your actual command:

runas /user:username C:\\Path\\To\\App.exe

Where username is a user of which you're sure that has the appropriate privileges. Note that you might be prompted for a pwd.

For any other issues, here's some related questions:

Community
  • 1
  • 1
Elias Van Ootegem
  • 74,482
  • 9
  • 111
  • 149