1

I am having issues executing a VBScript through Apache (WAMP) on Windows Server 2012. I am attempting to convert a Docx to PDF, and the script runs perfectly from the command line, but fails when running through PHP. Rather than posting the vbscript, I will provide a link to it: http://bit.ly/1gngYAn

When executed through PHP as follows, WINWORD.exe starts, as does the VBScript, and it hangs there and nothing happens. No PDF is generated (and I never see the ~temporary.docx hidden file pop in the directory).

I have tried just about every iteration of exec, system, passthru and COM ( 'WScript.Shell' ), and all have the same outcome.

To avoid "escaping" issues, I also tried executing the script though a .bat file so no arguments needed to be passed, and the outcome was the same.

Here is my current php code (convert.vbs is the code from the link above):

$obj = new COM ( 'WScript.Shell' ); 

$obj->Run ( 'cmd /C wscript.exe //B C:\Users\Administrator\Desktop\convert.vbs c:\wamp\www\fileconv\temp_store\52fa8272bf84f.docx', 1, false );
//I have tried different "window styles" too, and it doesn't make a difference

I also tried modifying the apache service user to run as administrator (this is not a production server), and enabled "Allow service to interact with the desktop", and it had the same outcome.

I have also made sure the directories had "full control" by everyone (reading, writing, executing, etc).

It runs perfectly if I run from the command line or with my ".bat" file.

Since it hangs (the script and word, not apache), I have looked at the event viewer in the control panel, but there are no events that pertain.

My questions is firstly, why is this happening, and secondly, if the first cannot be answered, is there a way that I can get a more in depth look at what is happening when the process is executed, as to further troubleshoot it? As of now, I have no data to review or output to see to help me troubleshoot.

Please feel free to ask for any details. I have tried many, many iterations to try to get this to work, searched high and low, and can't seem to come up with any answers.

I appreciate your assistance,

Louis

2 Answers 2

3

It took me a couple of days, but here is the solution I found:

I used PsExec - http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

The following flags are required: -h -i -accepteula -u -p

(I tried without the -h, -accepteula and -i, but no dice. This is running on Windows Server 2012 under WAMP)

Here is an example:

exec('c:\psexec\PsExec -h -i -accepteula -u Administrator -p '.$password.' C:\Windows\System32\CScript.exe //Nologo //B c:\wamp\www\fileconv\convert.vbs '.$filename)

Now it executes properly and as intended.

I hope this helps someone in the same situation!

PS The WScript.Shell method of execution I used in my question works just as well as exec(), except exec() waits until the process exits.

Sign up to request clarification or add additional context in comments.

Comments

0

You should use exec() function this is the url http://php.net/manual/fr/function.exec.php

1 Comment

Please read the question again - "I have tried just about every iteration of exec, system, passthru and COM ( 'WScript.Shell' ), and all have the same outcome". I have tried exec() and the means of execution via PHP don't appear to have any impact on the outcome.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.