Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP how to launch windows GUI application

Tags:

php

windows

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.

like image 600
Telvin Nguyen Avatar asked Oct 20 '22 18:10

Telvin Nguyen


1 Answers

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

like image 150
HelloWorld Avatar answered Oct 24 '22 13:10

HelloWorld