Page 1 of 1

Execute a .exe program from PHP on Windows using IIS

Posted: Thu Jun 14, 2007 3:14 pm
by L4E_WakaMol-King
Title pretty much says it all.

junction.exe is a simple command line tool to create symbolic links in Windows... similar to "ln -s" in Unix.

This is the code I am trying to use:

Code: Select all

<?php
	error_reporting(E_ALL);
	ini_set('display_errors', '1');
	
	$newsitename = $_GET['site'];

	// Create static link
	$command = 'C:\\Inetpub\\wwwroot\\Daxko\\includes\\junction.exe C:\\Inetpub\\wwwroot\\Daxko\\'.$newsitename.' C:\\Inetpub\\wwwroot\\Daxko';
	print($command);

	$WshShell = new COM("WScript.Shell");
	$oExec = $WshShell->Run($command, 0, false);
?>
It seems to work... sort of. I am testing this on my local box (Win XP, IIS), so when I visit the page, junction.exe appears in my task manager. But it just stays in my task manager. It should run for about half a second and then close (it's only one command to create a link). The link never gets created and junction.exe never finishes.

What am I doing wrong?

Posted: Thu Jun 14, 2007 3:59 pm
by nickvd
Why create a COM object?

exec() || system() || passthru()

Posted: Thu Jun 14, 2007 4:11 pm
by L4E_WakaMol-King
I've tried all of those already. No dice.

For example,

Code: Select all

exec('C:\\Inetpub\\wwwroot\\Daxko\\includes\\junction.exe');
returns
warning: exec() [function.exec]: Unable to fork [C:\Inetpub\wwwroot\Daxko\includes\junction.exe] in C:\Inetpub\wwwroot\Daxko\includes\common.inc(1342)"
The other commands return similar errors or hang the php processor in an endless loop.

Posted: Thu Jun 14, 2007 4:24 pm
by L4E_WakaMol-King
L4E_WakaMol-King wrote:I've tried all of those already. No dice.

For example,

Code: Select all

exec('C:\\Inetpub\\wwwroot\\Daxko\\includes\\junction.exe');
returns
warning: exec() [function.exec]: Unable to fork [C:\Inetpub\wwwroot\Daxko\includes\junction.exe] in C:\Inetpub\wwwroot\Daxko\includes\common.inc(1342)"
The other commands return similar errors or hang the php processor in an endless loop.
All the folders involved have been set to "Full Control" for all users, and so has cmd.exe. I realize this is a major security issue, but I am desperate to make this work, and will worry about exactly which permissions need to be in place after I get it working.

Posted: Thu Jun 14, 2007 4:56 pm
by nickvd
Is this going to be facing the public? i.e. on a public website?

Or is it for a company/personal intranet...

Posted: Thu Jun 14, 2007 5:30 pm
by WaldoMonster
To use exec() on IIS you have to give IUSR_xxx user Read & Execute permissions to cmd.exe.

Posted: Fri Jun 15, 2007 8:19 am
by L4E_WakaMol-King
nickvd wrote:Is this going to be facing the public? i.e. on a public website?
Or is it for a company/personal intranet...
Eventually it will be public.
WaldoMonster wrote:To use exec() on IIS you have to give IUSR_xxx user Read & Execute permissions to cmd.exe.
I've done that. The program launches when I visit the page, but never finishes (and thus does not accomplish what it's supposed to do). I have to terminate it using ctrl+alt+del.

Posted: Fri Jun 15, 2007 9:18 am
by volka
Have you tried to exec another application?
e.g.

Code: Select all

system('cacls.exe .');
You might not want to run cacls.exe without knowing what it does: http://www.microsoft.com/resources/docu ... x?mfr=true

Posted: Fri Jun 15, 2007 1:46 pm
by L4E_WakaMol-King
Yes. Same result.

Posted: Fri Jun 15, 2007 2:01 pm
by nickvd
If it's going to be public, why are you creating symbolic links... you realize that they wont get sent to the client...

Posted: Mon Jun 18, 2007 12:23 pm
by L4E_WakaMol-King
Yes, I know that. I'm using Drupal with clean URL's if that helps. If not, it's a long story, so just take my word for it that I need this.