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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With