Solved

Running COM WScript.Shell on PHP IIS6 Windows Server 2003

Posted on 2011-03-17
8
1,432 Views
Last Modified: 2012-05-11
I am trying to run the following PHP code on a Windows Server 2003 with II6 running php as isapi to convert pdfs to swfs.

<?php
flush();

echo "This is a test<br><Br>";
$software_path ="C:\\SWFTools\pdf2swf.exe" ;
$pdf_path ="D:\\Book\DMC\php\Test\PDF\\1.pdf" ;

$argument = "-o";
$swf_output ="D:\Book\DMC\php\Test\SWF\\1.swf" ;

$cmd =" $software_path $pdf_path $argument $swf_output";
echo $cmd;
$WshShell = new COM("WScript.Shell") or die("Could not start WScript");


$oExec = $WshShell->Run("cmd /C $cmd ", 0, false);
?>

Open in new window


I receive a 500 error when running the code. When I comment out
//$oExec = $WshShell->Run("cmd /C $cmd ", 0, false);

Open in new window

the code will run without the error, but of course the command is not exicuted.

$cmd echos to:

C:\SWFTools\pdf2swf.exe D:\Book\DMC\php\Test\PDF\1.pdf -o D:\Book\DMC\php\Test\SWF\1.swf

which does work perfecty in the command prompt.

I have tried other sample codes as well that try to run from the cmd promt, and get a 500 error. I have never needed to interface with the cmd propt with php before so I am not familiar with the requirements.

I did try to give IUSR read / write permissions on the server, but this did not solve the issue.

Thanks for the help.
0
Comment
Question by:dmccull2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 17

Expert Comment

by:Shinesh Premrajan
ID: 35164397
Did you tried executing the command using system or exec command.


0
 

Author Comment

by:dmccull2000
ID: 35168776
I tried both with no luck same 500 error. I also tried passthru. Passthu does not receive a 500 error but it is also not exicuted.
0
 
LVL 15

Expert Comment

by:pcsmitpra
ID: 35230766
Check the user (Identity) for the application pool holding the website for PHP Website. Go to c:\WINDOWS\system32\cmd.exe and add that user here with 'Execute' permissions. Try now it with your page.
PS: - It is RISKY.
0
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 
LVL 25

Accepted Solution

by:
Ron Malmstead earned 500 total points
ID: 35233058
Try adding the following to your web config

<identity impersonate="true" userName="Administrator" password="yourpass"/>


This will make IIS impersonate administrator when launching processes.  It would be preferrable to use a service account with admin privilages though.
0
 

Author Comment

by:dmccull2000
ID: 35233503
Thank you, both solutions worked on the test environment. I can see how this can be very risky to the security of the server. Now to find a way to do this more securely. Any suggestions would be greatly appreciated.
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 35233635
Well your web.config file should not be accessible from IIS.  Access to it is forbidden by default.

One risk is if you create a web process that can be exploited, as it is running under an administrative account.

Another is if you have multiple people with access to logon to the server itself, who can view this file and get the credentials right out of it.

0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question