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.

8
  • stackoverflow.com/a/1403260/426533 Commented Dec 19, 2013 at 8:08
  • possible duplicate of php How do I start an external program running - Having trouble with system and exec Commented Dec 19, 2013 at 8:08
  • @Sergey He stated that he tried everything listed in that Q/A. Commented Dec 19, 2013 at 8:10
  • @JonathonReinhart, "If you're expecting it to pop up a GUI, I'm fairly certain that you can't do that. ;) " Commented Dec 19, 2013 at 8: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 Commented Dec 19, 2013 at 8:14

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Any to run GUI program without psexec ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.