Carlos Infoster
Carlos Infoster

Reputation: 21

Call a Windows Forms .NET EXE from PHP

I've seen many posts on stackoverflow but none of them helped.

I was (am) trying to run a .NET Windows Forms application (it doesn't contain any forms/GUI/dialogs/so but because of the nature of app it has to be Windows Forms). I tried shell_exec(), exec(), passthru(), etc. but all of them failed (they take infinitely long time and PHP Script never terminates)

Then, I tried running a simple C++ (unmanaged) console application - it WORKED and returned correct output and return code.

Then, I thought, maybe I could call this C++ EXE and let it further call a Windows application (i.e. in C++ using SYSTEM("path_to_exe.exe");) It worked fine when I compiled it, but again,

when PHP calls this console (with new code to run a .NET EXE), PHP again takes infinte time and never stops. Why?

Is there any one way I can successfully run my .NET EXE on Server from PHP?

Thanks a lot!

Upvotes: 1

Views: 489

Answers (1)

HamZa
HamZa

Reputation: 14931

"Is there any one way I can successfully run my .NET EXE on Server from PHP?" : Your EXE is already running !

So the problem is in your .NET EXE, i don't know what kind of EXE it is but you may use AutoIt scripting to execute it and then close the process after X seconds, here's a snippet of code (don't forget to compile it):

Run("C:\Program Files (x86)\K-Lite Codec Pack\Media Player Classic\mpc-hc.exe"); // You may use a relative path !
Sleep(5000); // Wait for 5 seconds
ProcessClose("mpc-hc.exe"); // Close the process

Upvotes: 1

Related Questions