Getting WScript.Shell to Run on IIS Server [Answered]RSS

3 replies

Last post Dec 04, 2013 10:48 AM by billbell52

  • Getting WScript.Shell to Run on IIS Server

    Nov 30, 2013 03:26 PM|billbell52|LINK

    I posted this in the general forum before I realized there is a PHP forum. 

    I am trying to get Wscript.shell to run on IIS 7.5/PHP 5.5.4  (Windows 7 development machine).  It works perfectly on IIS Express (VS Express for Web).  PHP code is shown below.  User enters data on web form and clicks button.  Javascript sends AJAX request to server with info on which document to create.  PHP creates a job file with instructions and executes Word with addin that reads job file.  Word with addin (VBA) runs on server and creates docx/pdf files.  PHP sends back JSON object with details on files.  Javascript updates links to files.  This process works great on IIS Express.  When I run it on IIS it hangs.  IIS and IIS Express are using the same PHP install so .net is enabled and working.  So I am thinking that IIS either does not have some feature enabled or does not have permissions to something.  I added IIS_IUSRS to the Word exe and made sure IIS_IUSRS has execute permissions to the PHP code.  All other PHP scripts work perfectly.  I don't get any error message from IIS log files.

    Any ideas are appreciated.

    $t = time();
            $job = 'C:\temp\Job' . $t . ".txt";
            $fp = fopen($job, 'w');
            fwrite($fp, $cmd);
            fclose($fp);
            $job2 = 'C:\temp\Job' . $t . "a.txt";  // copy gets around some strange problem with Word opening file.
    		copy($job, $job2) or die("Unable to copy $old to $new.");
            
            $runWord = '"C:\Program Files\Microsoft Office\Office14\Winword.exe" "' . $job2 . '" "C:\userdata\tripq\trip-web\trip-web.dotm"';
    		//echo $runWord;
    		$WshShell1 = new COM("WScript.Shell");
    		$oExec1 = $WshShell1->Run($runWord, 7, true);



    Wscript php

  • Re: Getting WScript.Shell to Run on IIS Server

    Dec 02, 2013 03:57 PM|jeff@zina.com|LINK

    IIS Express is running as the logged in user, likely a local administrator account.  IIS runs in the process account, far more restricted.  IIS_Users is just a group and not involved in this, so remove it from the permissions.  It just opens a potential security hole.  You need to add the proper permissions for the proper account, probably the app pool account.  Please don't change the app pool account to have administrator rights, you'll open a really big security hole that way.

    Because you use PHP, you don't actually need ASP.NET either, although it can be used to provide some functions.

    Jeff

    Wscript php

    Have you Binged a solution before posting?
  • Re: Getting WScript.Shell to Run on IIS Server

    Dec 02, 2013 06:36 PM|billbell52|LINK

    Jeff, thanks for the reply.  I am not all that familiar with IIS.  On the test Windows 7 PC I have a standard IIS install the website is 'Default Web Site' and the application pool it uses is 'DefaultAppPool'.  It is set to .net 4.0 and the identity is 'ApplicationPoolIdentity'.  When you say "add proper permissions for the proper account" how do you do that?  This internal application is for a small company so I am not overly worried about a security hole.  Right now I am concerned about getting it working.  I simplified my PHP to 2 lines.

    <?php
    		$WshShell1 = new COM("WScript.Shell");
    		$oExec1 = $WshShell1->Run('"C:\Program Files\Microsoft Office\Office14\Winword.exe"', 7, true);
    ?>

    Wscript php

  • Re: Getting WScript.Shell to Run on IIS Server

    Dec 04, 2013 10:48 AM|billbell52|LINK

    Problem Solved!!!  Solution was amazingly simple.

    1. An Office product can only run under a user account.  It needs to load user settings.

    2.  Solution was to have the app pool run under a custom account.

      Right click the correct app pool.  Click advanced settings.  Under Process Model click on Identity and add a custom user that can run Word.

    I know some may cringe at this solution.  Please note this is for a small intranet app.  So far tests have seemed reliable.  MS recommends using XML and their Open XML SDK.  This approach produces docs that are 10X as large.  Completely unacceptable.

    Wscript php