Execute a .exe program from PHP on Windows using IIS

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
L4E_WakaMol-King
Forum Commoner
Posts: 26
Joined: Wed Jun 14, 2006 10:54 am

Execute a .exe program from PHP on Windows using IIS

Post 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?
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Why create a COM object?

exec() || system() || passthru()
L4E_WakaMol-King
Forum Commoner
Posts: 26
Joined: Wed Jun 14, 2006 10:54 am

Post 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.
L4E_WakaMol-King
Forum Commoner
Posts: 26
Joined: Wed Jun 14, 2006 10:54 am

Post 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.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Is this going to be facing the public? i.e. on a public website?

Or is it for a company/personal intranet...
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

To use exec() on IIS you have to give IUSR_xxx user Read & Execute permissions to cmd.exe.
L4E_WakaMol-King
Forum Commoner
Posts: 26
Joined: Wed Jun 14, 2006 10:54 am

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
L4E_WakaMol-King
Forum Commoner
Posts: 26
Joined: Wed Jun 14, 2006 10:54 am

Post by L4E_WakaMol-King »

Yes. Same result.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post 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...
L4E_WakaMol-King
Forum Commoner
Posts: 26
Joined: Wed Jun 14, 2006 10:54 am

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