1

I am trying to run an exe file on my AWS Windows Server 2012 Instance using exec() function of PHP to execute command. But it makes my browser to show loading indefinitely. Command runs perfectly when I execute it on my server. When I run

echo exec('whoami');

It returns account username. So some commands are working through php. But when I run my executable file like:

echo exec('myfile.exe');

It makes browser to keep on showing loading . (I have added path of my exe to environment variables so that I can directly access my exe from command prompt)

Any help is appreciated. Thanks

Amol Bharmoria
  • 239
  • 4
  • 23

1 Answers1

0

What I wanted to do here is, open an exe file on my server through a browser. I managed to do it using following php code which I found in an answer :

shell_exec('SCHTASKS /F /Create /TN _notepad /TR "notepad.exe" /SC DAILY /RU INTERACTIVE');
shell_exec('SCHTASKS /RUN /TN "_notepad"');
shell_exec('SCHTASKS /DELETE /TN "_notepad" /F');

This will open notepad on your server. You can replace path to your exe file with notepad.exe This worked for Windows 8.1, Windows 10 and Windows 2012 Server

You can also try following steps to enable Apache service to run desktop application:

Start->Run, type "services.msc" to bring up Services control (other ways to get there, this is easiest IMO)
Locate your Apache service (mine was called "wampapache" using WampServer 2.0)
Open the service properties (double-click or right click->properties)
Flip to the Log On account and ensure the checkbox titled "Allow service to interact with Desktop" is checked
Flip back to the General tab, stop the service, start the service

Here is the link to question which I followed for solution : php How do I start an external program running - Having trouble with system and exec

Hope it helps someone else.

Community
  • 1
  • 1
Amol Bharmoria
  • 239
  • 4
  • 23
  • me too facing the same issue now. was the issue because of web user access? I used your solution, its not even working in cmd as its showing access errors – Thejas Jul 26 '16 at 11:26