Page 1 of 1

shell_exec to run program in foreground on windows

Posted: Mon Jan 22, 2007 6:30 pm
by Mctittles
Hello all. Been looking for a couple days on this, so thought I would try this forum. I am trying to run some programs on a local server using php and IIS on windows XP. What I really need to do is execute programs WITH PARAMETERS in flash but flash doesn't allow that so I thought I would try php as the middleman. Anyway, it DOES load a program, but not for the current user. When I test this:

shell_exec ("C:/windows/notepad.exe");

I don't see the notepad open, but if I check the tast manager there is a notepad.exe process in there and it is running under "System" for the username. I've tried changing IIS to use my current login under the DIRECTORY SECURITY tab but it doesn't seem to make a difference.

Anyone know a solution to my problem? Thanks for any input.

-Shawn

Posted: Mon Jan 22, 2007 7:24 pm
by Ambush Commander
As far as I know, PHP can not invoke GUI applications. Someone else feel free to prove me wrong though.

Posted: Mon Jan 22, 2007 8:28 pm
by printf
You shouldn't have to use the full path, because notepad by default is included in the system path.

Code: Select all

<?php

system ( 'notepad.exe' );

?>
Also because you don't close STDIN, STDOUT, STDERR, the page will hang until you close notepad. You can only close it via COM or .NET by killing the process or by opening and closing notepad as an $object = new COM ( 'app.id'); If your needing interaction then use PHP WIN32 or use the COM interface.

pif

Posted: Mon Jan 22, 2007 9:01 pm
by Jenk

Code: Select all

<?php

sell_exec('notepad "your arguments here"');

?>

Posted: Mon Jan 22, 2007 9:44 pm
by Mctittles
Thanks for the help. So far any methods with or without still open notepad as is seen in task manager, but still is under the user "system" so not visible to the user. I'm not really needing to open notepad in my program, but just using it as a test. I have have tried a few different ways to do this but nothing I can use just yet. See, flash does have an option to execute a program, but with many limitations including not being able to give it params. I can successfully open a program with a .vbs script or a batch file and have it shown in the foreground, but I can only send parameters to a .asp or .php script from flash. When trying to use .php or .asp to open programs they always show up under another user in task manager. The program I need to open will need many different commands so I cannot write a .vbs or shell script for each possible combination of parameters as it would be too many.
If I can't get this to work the only other option I can think of is have a .php or .asp script create a batch file and then have flash open this file after it is created. This just seems like a very crappy way of doing this though.

Posted: Tue Jan 23, 2007 7:59 am
by feyd
Last I checked, Flash executed pretty much solely on the client-side, whereas PHP and ASP run solely on the server-side. Where do you want to run this program?

Posted: Tue Jan 23, 2007 8:29 am
by Mctittles
It's going to run locally, this computer won't even be connected to the internet. I want to make a game selector that has some cool animations and stuff, and I can do everything I want with a flash projector file except for starting the programs. Of course I could start them in a C..something program but I know flash Much Much better and don't have time to learn just for this little project...