Hello all: One of my PHP scripts is designed to call an application as a command-line invocation. The app loads successfully, but only in the background. I see it listed as a running process in the Windows Task Manager, but the window containing the app I'm calling doesn't ever actually appear. Here's a snippet of code that I'm using. As an example, I'm trying to bring up a new instance of FireFox: $path = "C:\\progra~1\\mozill~1"; $file = "\\firefox.exe"; chdir($path); $call = $path.$file; pclose(popen('start /b '.$call.'', 'r')); Code (markup): This problem occurs for any kind of call to a Windows app. The weird thing is, if I echoed the $call string, which would look like this once concatenated and printed to STDOUT: C:\progra~1\mozill~1\firefox.exe ...copied and pasted back into a command line, it behaves perfectly, bringing up an instance of Firefox. I'm pretty sure this is some kind of security feature within Apache and/or PHP which prevents a script from highjacking the operating system locally by invoking hidden viruses/worms/trojans, etc. Normally, I would consider this a very good thing and wouldn't think twice about its usefulness in protecting machines and users. However, in the particular application I'm working on, I do need to be able to call new Windows apps from a PHP script in this manner (or any other that may suffice). Is there some quick & dirty configuration setting out there that I can tweak to get this to work? Currently running: Apache v2.2.6 PHP v5.2.4 both from the integrated XAMPP 1.1.1.2 bundle installed on Windows XP Service Pack 2 w/ latest patches Any assistance appreciated.
That doesn't really look like the right function to use for starting a program. It will work but it's not designed for that purpose. I think you might be better off with "exec()". From the php manual: You may also end up being very confused if you are developing this on your home machine and expect it to run the same way on your server. This call will open Firefox on the server, not the user's machine. If this is what you were expecting, all well and good, but if not, you might ant to re-think what you are trying to achieve. I don't do Windows, so you'll have to forgive my ignorance of all things Microsoft but does "start /b" mean "start in the background" ?
Yes - the path shown with the tilde characters "~" qualifies as the old 8-character path name. The app is coming up, just not visibly, which indicates it is finding it.
Tried that and same problem - only runs in the background along with the added issue of having an extra cmd.exe process running. The popen/pclose command grouping is designed to use the cmd.exe shell to fire off an application and then close down the shell without killing the app. This aspect of it seems to work, just without showing the actual app on the desktop. I also tried "system()" call with identical results as "exec()". No worries there. Both the Windows application being called and the actual web site are being brought up on the same server and accessed locally only through RDP (Remote Desktop Protocol). This is by design based on the requirements I have. Heh...yes it does - I just discovered that this morning based on this email. That's the problem when you copy-paste sample code without knowing exactly what it does. I removed that and added some extra parameters which should help, winding up with a command that looks like this now: start C:\progra~1\trayco~1\traycolor.exe /MAX /NORMAL /K Where /MAX is "run maximized", /NORMAL is run as normal priority class and /K forces the window to remain after the command has been run. Still no love running this out of PHP. This exact same command, however, when copied and pasted directly into a command line in cmd.exe brings up the application exactly as I would expect it to. This really feels like a PHP or Apache anti-hijacking security setting to me.
Tried it. Still doesn't seem to work - it starts the process in the background but then freezes the PHP app that's calling it until the process is forcibly ended. Also tried it with exec() and same reaction.
Yes, when I run a test.php with that code from the command line, it runs fine and brings up a new FireFox window. Running that same script in a browser, however (I tried it both in FireFox and Internet Explorer), and it does nothing more than bring up an additional instance of FireFox in the background and doesn't actually open a window, which has been my problem all along. If I recall how web servers work, there is a user id assigned to the web server process itself. I'm thinking that if the web server's user does not have access in the operating system to invoke external processes, this would explain what I'm experiencing. I think I need to grant access to that particular user, but I'm not sure how. I've been a developer a long time, but my Windows admin skills are mediocre at best. Anyone run into this before?
Well, I found the solution to the problem in case any one else runs into it in the future. Using the Windows Services Manager, go into both the Apache Server service and the Apache2.2 service. Under each properties dialog box, click on the "Log On" tab. Under "Local System account", click on the "Allow service to interact with the desktop" check-box to turn it on, then hit "OK" and restart the service. By default, this setting is turned off. After turning it on, it enables the service to fully invoke the Windows application to the desktop. Thanks all for your suggestions - this matter can be considered closed.
I now have a follow-up question to this thread. I moved the system over to its final resting place from Windows XP to Windows 2003 Server and I'm having this problem again! I turned on the "Allow service to interact with desktop" check box in the Apache service preference like I did in XP that made it work originally, and the same old thing happens - application gets called, runs in the background and doesn't actually get invoked to the desktop. I know that Windows 2003 has a bunch of extra security "features" that prevents a lot of stuff from happening out of the box and this is likely one of them - some additional setting that needs to be activated elsewhere. Is there some other service that exists in 2003 and not XP that also needs to "interact with the desktop" in order for this to function properly? What am I missing? I'm not a Windows admin and this stuff genuinely mystifies me. Any help appreciated. Thank you!
Solution found, for anyone interested. The shortcut for Remote Desktop Connection that I'm using to access the Windows 2003 server remotely required a "/console" parameter following the shortcut link string. This allows applications to be invoked if a user is running RDC. If I was logging directly into the machine, I would not have had this issue.
I am facing an issue which is something similar. In my case, I would like to launch the browser[IE] and navigate to a website which has activex component in it. But it looks like the browser is launched as SYSTEM user and browser has limited privileges in that mode and fails to navigate/download activex and it hangs eventually. I lowered the security in the hanged internet explorer and then everything goes fine from next time onwards. However I would like to know how to this automatically?