ColdFusion 'Run As Service' Vs 'Run in Console'
coldfusion, console-application, ms-word, vbscript, windows-server-2008-r2
Solution
I have found the answer to my problem.
I tried to go back to basics and check the issue from all the associated components.
- CF
- VB Script Code
- Word Application COM
- Windows 2008 R2
CF is just executing the script fine if there is no Word COM involved. So, i felt, it has nothing to do with the access basically.
VB Script code is fine when executed from COMMAND window, but not when we call it from a Service (the CF Service). So, I ruled out VB Script too as the trouble
Word Application COM - same as VB Script
Windows 2008 R2 - Culprit nabbed.
Reason
It is a due to a bug in the Windows 2008 server. It has something to do with the user profile. Even when I say, Log On As on my service, the COM created always was using the LOCAL SYSTEM account. I found this in the Proc Mon.
Starting with that point, I checked in the MS Forums for 2008 and problems related to COM objects.
There are many articles, but one had clearly the same problem as mine, but with Excel.
The answer is - "For office automation (accessing via script and non-window based operation), one needs to have a folder named 'Desktop' in the system profile."
Its detailed here. (Search for 'H Ogawa')
Once again, hard work and stackoverflow talk pays good. :)
Thank you all for you help.
Problem
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.