shell_exec to run program in foreground on windows

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mctittles
Forum Newbie
Posts: 3
Joined: Mon Jan 22, 2007 6:21 pm

shell_exec to run program in foreground on windows

Post 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
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

As far as I know, PHP can not invoke GUI applications. Someone else feel free to prove me wrong though.
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post 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
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Code: Select all

<?php

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

?>
Mctittles
Forum Newbie
Posts: 3
Joined: Mon Jan 22, 2007 6:21 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
Mctittles
Forum Newbie
Posts: 3
Joined: Mon Jan 22, 2007 6:21 pm

Post 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...
Post Reply