PHP Is it possible to run a GUI program through exec ()?

I need to start a web browser (chrome - firefox ..) using exec

I tried to do this using a bat file (this method is mentioned here )

C:\Users\farok\AppData\Local\Google\Chrome\Application\chrome.exe www.google.com 

when I open a file using windows, everything goes fine, but nothing happens when I open it with exec

and I tried to do this using the jar file of the BrowserControl class

 BrowserControl.displayURL("www.google.com"); 

and same as bat file, so is there any way to do this?

note: im using wamp 2.2, Apache 2.0, PHP V5.3.8

Update

I found that after running this command

 exec('"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" "www.google.com" 2> errors.txt'); 

The firefox add-on is open in the task manager, but the browser interface is not visible .. any ideas?

+4
source share
5 answers

I am not an expert on Windows, but I think you need to enable desktop interaction , which is not easy / possible if the parent process runs as a Windows service. php runs inside the apache process, which is probably running as a service.

Try stopping the service and manually running httpd.exe , and then the following works for me on win7 when I request a script through the localhost url via apache. my php interfaces with apache via plain old cgi.

 exec('"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" "http://stackoverflow.com/"'); 

pay attention to the use of quotation marks.

+4
source

Probably the easiest way is to use COM (I assume that it will only be executed locally on a Windows machine):

 <?php function _exec($cmd) { $WshShell = new COM("WScript.Shell"); $oExec = $WshShell->Run($cmd, 0,false); echo $cmd; return $oExec == 0 ? true : false; } _exec("youexe.exe"); ?> 

Taken from here

+1
source

I decided that by disabling the apache service on Windows and starting apache with httpd.exe, then you can use exec () to open any GUI window program.

 exec("Path_to_mi_program.exe" "file_to_open"); 
+1
source

so this is another good workaround I found here , the idea is to create a scheduler that runs the program you need and invoke it with the command

hope this help:

 shell_exec('SCHTASKS /F /Create /TN _notepad /TR "notepad.exe" /SC DAILY /RU INTERACTIVE'); shell_exec('SCHTASKS /RUN /TN "_notepad"'); shell_exec('SCHTASKS /DELETE /TN "_notepad" /F'); 
+1
source

This is only about users. When you run the program, it works as a system user . I tried runas /user:myusername blabla.exe , but it returned the password for myusername and exited.

 $deneme = shell_exec('runas /user:myusername C:\Windows\Temp\putty.exe'); echo "$deneme"; 

he is back:

 myusername iΓ§in parolayΔ± girin: (english: password for myusername) 
0
source

All Articles