Linux PHP - expert advice needed

Status
Not open for further replies.

painkiller

Contributor
im trying to call an exe file (printer software) from a php page:( i have tried exec, system, passthru functions without any luck. i am running win xp pro with iis 5.1 as test server. the actual production server will be win server 2003 with iis6. can any one help me out with code snippet or any linkz.

EDIT: @mods...feel free to move it to programming category if u think thats the right place for this thread :)
 
Should have been posted in 'Programming' section. anyways..

Im not an expert in php, but used proc_open() for some work I needed done. But this was in linux. There is a hint on how it works on windows in the php ref page of proc_open. popen might also be useful.

Post back if you have any success.
 
google for com interface in php.

I'm not in a position right now to get in depth, but you should be able find enough resources on that. :)
 
ok, i have exec, popen, proc_open functions over notepad.exe but still no success :( i have also tried it by copying notepad.exe to C:\PHP folder but nothing happens. here is the code along with error messages:

PHP:
<?
error_reporting(E_ALL);
/*
exec ("notepad.exe");
//RESULT
//Warning: exec() [function.exec]: Unable to fork [notepad.exe] in C:\Inetpub\wwwroot\html\thomson\openapp.php on line 4

//======================================================

/*
popen ("notepad.exe","r");
//RESULT:
//Warning: popen(notepad.exe,r) [function.popen]: No error in C:\Inetpub\wwwroot\html\thomson\openapp.php on line 6
*/

//======================================================

/*

$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
   2 => array("file", "temp.txt", "a") // stderr is a file to write to
);

$cwd = '/tmp';
$env = array('some_option' => 'aeiou');

$process = proc_open('notepad.exe', $descriptorspec, $pipes, $cwd, $env);

// RESULT
//Warning: proc_open() [function.proc-open]: CreateProcess failed in C:\Inetpub\wwwroot\html\thomson\openapp.php on line 17
*/

?>

i think it has something to do with file permissions as well.
 
Try doing a phpinfo() and see if there's some option for execution of a program there or not, you might find some option that could have been turned off.
 
ok, i played with cacls and permissions and managed to start the various exe files(namely notepad and calc) but they are only showing up as process in task manager. i mean frontend windows for these programs are not showing up. i had to kill these process using task manager. what im missing here. im using following code:
PHP:
<?
error_reporting(E_ALL);
$shell = new COM("WScript.Shell");
$shell->Run("calc.exe");
$shell = null;
?>
 
random2 said:
Dude, give full path of the executables and try. Will test and let you know.

the exe file is actually running but not showing up any GUI :@ task manager is the only way to see this process and kill it.
 
ok, this might solve it - Go to services in control panel right click on apache -> Properties -> Log On and check the 'Allow service to interact with desktop' then apply

restart apache and try again. Let us know how things go.

PS: It worked for me. opened up cpuz through popen.
 
random2 said:
ok, this might solve it - Go to services in control panel right click on apache -> Properties -> Log On and check the 'Allow service to interact with desktop' then apply

restart apache and try again. Let us know how things go.

PS: It worked for me. opened up cpuz through popen.

im running win xp pro sp2 /iis 5.1 buddy
 
^^ nope still no luck, this is what i have done:
1. i changed "IIS Admin" service setting as suggested by random2
2. copy cpuz.exe and cpuz.ini files to windows\system32 folder and grant full control to 'internet guest account (IUSER_SPARTAN1)'.
3. ran following code:
PHP:
error_reporting(E_ALL);
$handle=popen ("cpuz.exe","r");
echo "'$handle'; " . gettype($handle) . "";
pclose($handle);
4. now, cpuz.exe is getting started by this code but it is still not showing any GUI just running as a process in task manager :@
5. any clue? one thing to notice: cpuz.exe process is running under 'IWAM_SPARTAN1' username
 
Well, I have tried it quite a few times and even with the exact same thing you have posted above. And it works on Apache. (win xp 64bit)

But there is a reason for this interactive thing to be switched off by default. By enabling this, you will be giving your web server/code running through it almost full access as the user running the pages on a browser. This is not a good thing.

Im not sure what you are trying to do, but a bit wider info on your problem might bring in more ideas towards solving this.

PS: One more thing, Im not sure how well this works on a client machine running this code from a server. What ive tried is both server and the browser on the same pc. Im too tired to fire up a vm :(
 
what im trying to do is to open up a hp printer-scanner application thru a simple hyper link. my client wants to have an icon which will open up this application upon clicking. since this application will be installed in a LAN, no worries about security.
 
ok, but the hyper link will open the application on the server. Is that what you want?

Im really an idiot for posting about the security thing that way. What I should have meant was that you would be making the server more vulnerable. Anyways, its your take.

Will try to test when im a bit saner, badly need some sleep.
 
Status
Not open for further replies.