Is it possible to start an application from PHP so that an actual window pops up and can be used normally?
[RESOLVED] start application to use normally?
browser window on client machine? php is server side but you can echo javascript to do it.
To clarify, by application I mean binary or executable, and yeah the program would be started on the server.
When I run a program with something like system or exec, there is no visible window. I'm wondering if there is a way for the window to show up so the program can actually be used by a human.
Read my comments at the top if you're using Apache as a service - this might work for you
<?php
/**
* For a command like notepad to show a window when running under apache as a service
* have to set the option 'Allow apache to interact with desktop' in the log on tab
* in services. Restart the service if you change it.
*
* 12/09/2006
*/
echo "I start at: ".date('r').'<br />';
shell_it('notepad.exe', 1, true);
echo "I'm done at: ".date('r').'<br />';
/**
* exec, shell_exec and backticks getting you down?
*
* @param string command to run
* @param int window style
* @param bool wait before returning - set to false and it will run in bg
*/
function shell_it($cmd, $winStyle = 0, $waitOnReturn = false)
{
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run($cmd, $winStyle, $waitOnReturn);
$WshShell->Release();
return $oExec;
}
/*
Ok modes Actually here: http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/wsh/htm/wsMthRun.asp
0 Hide the window and activate another window.
1 Activate and display the window. (restore size and position) Specify this flag when displaying a window for the first time.
2 Activate & minimize.
3 Activate & maximize.
4 Restore. The active window remains active.
5 Activate & Restore.
6 Minimize & activate the next top-level window in the Z order.
7 Minimize. The active window remains active.
8 Display the window in its current state. The active window remains active.
9 Restore & Activate. Specify this flag when restoring a minimized window.
10 Sets the show-state based on the state of the program that started the application
If bWaitOnReturn is set to TRUE, the Run method returns any error code returned by the application.
If bWaitOnReturn is not specified or FALSE, this method immediately returns to script execution
rather than waiting on the process termination (and returns an error code of 0)
Specifying the bWaitOnReturn parameter allows you to run programs synchronously (one at a time).
Using 0 never shows a phpcli window at all in the taskbar
Using 7 shows it, but just in the task bar, it doesn't focus
*/
?>
Oh right, my Apache is running as a service. I guess it makes sense that I wouldn't be able to see the windows. I allowed Apache to interact with the desktop and all is well now. It's always something simple...
Thanks!
I don't even need any of that code, but it looks handy so I'll keep it in mind. Thanks again.
Don't forget to mark this thread resolved.