5

Sorry if it seems the silly question. I could not launch windows GUI application by PHP any way. I have tried any workaround that I have found out from the similar questions but they did not work at all.

My command:

$cmd = 'E:\soft\Notepad++\notepad++.exe E:\text.php';

I can run that command by the Window Command Line tool and it worked fine, the notepad++ launched and opened the GUI with the expected content. I would like to do that in php

I have opened the windows services and set the option "Allow service to interact with desktop" (checked) for "wampapache" service and restart it as well.

I have tried with each of following commands:

pclose(popen("start /B $cmd", "r"));

OR

system("start $cmd");

OR

exec("C:\\windows\\system32\\cmd.exe /c START " . $cmd);

OR

$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run($cmd, 0,false);

All of them gave me the same of result: it just ran the application IN THE BACKGROUND, I could see that app process that is running by looking at the Task Manager of Windows, but the GUI DID NOT DISPLAY.

My PHP version is 5.4.3

Any help is appreciated.

Telvin Nguyen
  • 3,569
  • 4
  • 25
  • 39
  • http://stackoverflow.com/a/1403260/426533 – Sergey Dec 19 '13 at 08:08
  • possible duplicate of [php How do I start an external program running - Having trouble with system and exec](http://stackoverflow.com/questions/1403203/php-how-do-i-start-an-external-program-running-having-trouble-with-system-and) – Sergey Dec 19 '13 at 08:08
  • @Sergey He stated that he tried everything listed in that Q/A. – Jonathon Reinhart Dec 19 '13 at 08:10
  • @JonathonReinhart, "If you're expecting it to pop up a GUI, I'm fairly certain that you can't do that. ;) " – Sergey Dec 19 '13 at 08:13
  • I have seen that ticket and your answer as well, Sergey. Your answer is that is impossible to do while other guy told that it is doable. I was confused and kept trying to find the answer around. Is it true that no way out? Using the Windows schedule is not option with me, thanks – Telvin Nguyen Dec 19 '13 at 08:14
  • @Sergey Did you even look at the other answer, which is more up-voted than the accepted one? – Jonathon Reinhart Dec 19 '13 at 08:15
  • You can start a GUI application. The answer is here: http://stackoverflow.com/a/8170050/1204690 – Amged Rustom Dec 19 '13 at 08:18
  • Yes, I have tried the workaround from Chris in that question, but I couldn't make it work. You can see that I have mentioned about it in my question before. Thanks for your reference anyway. – Telvin Nguyen Dec 19 '13 at 08:20

1 Answers1

3

I assume that PHP is running within Apache, which in turn is a service.

Now starting any application from service will not have its GUI displayed, as Service is running in separate session which does not allow interaction with users Desktop.

See this answer for more details: Service starting a process wont show GUI C#

However there can be other ways to achieve this.

  1. Create a custom C++ (or equivalent) application that will create your target GUI application for the given user. The answer How can a Windows service execute a GUI application? explains CreateProcessAsUser() for that. This method will require user name and password to be specified.

  2. Create custom client-server kind of application. The server part will always be running inside in User mode where the GUI needs to be displayed. And the client will be called from PHP. When client is invoked, it will signal the Server part using IPC like event. Server can start the GUI application in turn.

  3. Use the Microsoft's PSEXEC utility to start the process in GUI. However this will need user name, password and session id.

    psexec.exe \\REMOTE -u USER -p PASS -i SESSION -d C:\Windows\Notepad.exe

    SESSION is the session id (Use Task Manager -> User Tab to see your session ID)

    USER, PASS is the user name and password for the user

Community
  • 1
  • 1
HelloWorld
  • 158
  • 9