PHP - Any chance to run GUI program through exec()?

百般思念 提交于 2019-12-04 10:08:17
goat

I'm no windows expert, but I think you need to allow desktop interaction, which isn't easy/possible if the parent process runs as a windows service. php runs inside the apache process, which you probably have running as a service.

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

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

note my use of quotes.

I solved that by disabling apache service on windows and start apache with httpd.exe After that can use exec() for open any GUI windows program.

exec("Path_to_mi_program.exe" "file_to_open");

so this is another good workaround i found here, the idea is to create a scheduler that execute the program you want and call it using 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');

Probably the easiest way is to use COM (I assume it will only run locally on a Windows computer):

<?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

Melih Yıldız'

It's just about users. When you run a program, it runs as system user. I tried runas /user:myusername blabla.exe but it returned password for myusername and exit.

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

it returned:

myusername için parolayı girin: (english: password for myusername)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!