Question
What is the difference that arises in terms of permissions when CF runs as a service Vs CF runs in a console mode?
History
I have a code that creates COM objects for Word.Application and use them to convert a DOC to PDF. But when I moved to CF 10u8 (64b), the logic broke. I have checked the inter webs, played around changing the java.library.path={} values, permissions, and all possible hints to make it work; but to no success. I found an entry in the Adobe Bug Base to confirm that jintegra\bin\ntvinv.dll is designed to work in a 32b environment.
So, I resorted to use the VB Script mode to shift my CF Code into a VB Script and do my DOC to PDF conversion.
The Problem
The code in VB Script came out beautiful and it does what I need in a jiffy. It seems okay until I called this .vbs from <cfexecute>. It processes for ever, times out and nothing shows up + there are abandoned Process of WINWORD.exe in the Task Manager.
I tried writing the arguments into a batch file and call it. This time it runs immediately, but nothing happens. I checked the logs and it reads
Microsoft VBScript runtime error: Object required: 'wdocs.Open(...)
I called the batch file from command prompt and it executes with no errors. My DOC -> PDF Conversion is done.
So, this time I have changed the ColdFusion Service 'Log on As...' permission from 'Local System Account' to an Admin user account of the system and started it. I get,
The CF 10 Application server service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs
So, end of road there. I have tried playing with option of 'Allow service to interact with desktop'. But nothing improved.
Finally, I tried to run the CF from bin\cfstart.bat file. It has coldfusion.exe -start -console. The command window showed up and CF started. This time, the <cfexecute> works and the conversion happened. No errors are seen. I'm puzzled on why this is happening. What difference did running it as a service with system account(who logged on) Vs running as a Console with the same user account come up? What am I missing to understand?
Debug
I have created a LOCAL user account on the server and used that both in 'Log on As...' and also by logging into the system with the same account. In both cases, its the same story as above.
I feel its a permission problem and what I could not figure out is where and why is this occurring? especially why in service mode and not in console mode?
Note: Before going to VBS, I have tried using the <cfdocument format="pdf" ... >, but it throws exceptions because of some specific formatting in my DOC. So, it not an option for now.
Credit: My Code in VBScript is derived from here
Update
Here is my code that you can test with.
Command line code
/c <pathToTheScriptFile>/doc2pdf.vbs <absolutePathTo>aWordDocument.doc o/:<absolutePathTo>finalPDFDocument.pdf
The doc2pdf.vbs takes two arguments. the first will be the wordDocument name (with path) and second is optional PDFDocument name. If the optional argument is not passed, the same name of the wordDocument is given to the PDFDocument.
ColdFusion code
<cfexecute name="c:\windows\system32\cmd.exe" arguments="#commands#" outputFile="output.txt" errorFile="error.txt" timeout="20"/>
or you also try using the Java run time object
<cfscript>
objJR = createObject("java", "java.lang.Runtime").getRuntime();
result = objJR.exec(commands);
writeDump(result);
</cfscript>
To run it in your local machine, you need
- an installation of MS Word 2007 or higher with a 'Save As PDF' plugin attached.
- the VBScript (get this from here)
- CF 10. I'm on Update 8. This works on any update level.