2

I have tried launch an external application installed in the C:\Program Files (x86)\Hewlett-Packard\HP MyRoom\MyRoom.exe using php.

SAMPLE 1 : I'm using exec function and popen and system. But exec function is not executing the code next to the exec command until the application is closed.

**CODE :** 
exec('"C:\Program Files (x86)\Hewlett-Packard\HP MyRoom\MyRoom.exe" ');

SAMPLE 2 : WHen i use the popen ,it is displaying a cmd window instead of application.

CODE : 

pclose(popen('start   "C:\Program Files (x86)\Hewlett-Packard\HP MyRoom\MyRoom.exe" ' ,'r'));

OR

system(' start "C:\\Program Files (x86)\\Hewlett-Packard\\HP MyRoom\\MyRoom.exe"  ');

OUTPUT : enter image description here SAMPLE 3 :

When i user this code, it is return string output.

CODE :

system(' start /B "C:\\Program Files (x86)\\Hewlett-Packard\\HP MyRoom\\MyRoom.exe"  ');

OUTPUT :

Microsoft Windows [Version 6.3.9600] (c) 2013 Microsoft Corporation. All rights reserved. C:\xampp\htdocs\projects\drupal\hpedu\reference>
Any help would be greatly appreciated. 

SAMPLE 4 :

WHen i try this code, it is not returning anything.

CODE :

  exec("start /B  \"C:\\Program Files (x86)\\Hewlett-Packard\\HP MyRoom\\notepad++.exe\\MyRoom.exe\"  ");
Ananth
  • 1,520
  • 3
  • 15
  • 28

2 Answers2

2

try

exec('"C:\Program Files\FileZilla FTP Client\filezilla.exe"');

as it is working on my end.

also for script to stop execute try putting a "exit;" after exec command. and if u wnat to execute lines written after exec command then use

exec('"C:\Program Files\FileZilla FTP Client\filezilla.exe"|at now'); 
echo "after quitting the program"; 

but it would work only after the executed program is closed.

Tushar Dave
  • 220
  • 1
  • 5
  • actually, the above code is working, But the issues is that i have to execute several other code next to the exec function. But when i use exec(), the execution stops at exec , it is not moving to next line. Ex: exec(); echo "Success" ; . In above example it output success. it is in loading stage only. – Ananth May 26 '14 at 13:41
  • well the closes solution to this as far as i think would be to use: exec('"C:\Program Files\FileZilla FTP Client\filezilla.exe"|at now'); echo "after quitting the program"; but it would work only after the executed program is closed. i have also edited my answer for this – Tushar Dave May 26 '14 at 14:10
  • Yeah. In my question, i mentioned that issues with exec already. I want to echo the "after quitting the program" text before quitting the program – Ananth May 26 '14 at 14:17
0

This will never work AFAIK, even if you do a 'login as admin' command first to make sure you have admin rights, there is no way to execute an external .exe file.

Kevin Op den Kamp
  • 565
  • 1
  • 8
  • 22
  • when i use this exec('"C:\Program Files (x86)\Hewlett-Packard\HP MyRoom\MyRoom.exe" ');, it wil working fine. But the issues is , it is not stoping execution of the php script, until the application closed – Ananth May 26 '14 at 13:11
  • True but that has nothing to do with running the command from PHP using exec or similar. It just won't work, probably for security reasons. It took me ages to come up with a workaround as I had a similar problem: http://stackoverflow.com/questions/21731033/open-file-in-vlc-via-html-js-or-php Some suggest giving admin rights to PHP/apache etc. but this doesn't change a thing...not for me at least – Kevin Op den Kamp May 26 '14 at 13:12
  • You can open any .exe file within php on a windows machine, even use COM class. Activate in php.ini the com_dotnet extension $WshShell=new COM("WScript.Shell");$oExec = $WshShell->Run("cmd /C $cmd ", 0, true); – wHiTeHaT Aug 20 '23 at 22:49