4

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.
Sanjeev
  • 1,838
  • 1
  • 16
  • 28
  • *It processes for ever, times out and nothing shows up + there are abandoned Process of WINWORD.exe in the Task Manager* Try appending [`/c`](http://stackoverflow.com/questions/515309/what-does-cmd-c-mean) to the beginning of your arguments. That directs cmd.exe to run the command and exit. (Also, CF10 probably does not need it but it would not hurt to redirect stderr to stdout too ie `2>&1`). `` – Leigh Apr 03 '13 at 15:35
  • Also, could you post a small, self-contained, repro case that we could test? – Leigh Apr 03 '13 at 15:37
  • @Leigh I have added my code. Also, I have tried the /c and 2>&1 suggestion before hand itself. it did help to kill the WINWORD. Just a thought, I feel with the new attribute (errorFile) for cfexecute, it wont be big help to use the 2>&1. – Sanjeev Apr 04 '13 at 02:39
  • Yeah, like I mentioned redirecting stderr probably is not necessary, but could not hurt as a troubleshooting step. Is the real code using absolute paths for all of the files? (Looks like there is no path for the input .doc). Also, all of paths refer to the local server drive (ie not a mapped drive or anything), right? I will try the code when I am near a CF10 install tomorrow. See what results I get. – Leigh Apr 04 '13 at 03:45
  • @Leigh, yes the path is absolute. I have updated the code now. – Sanjeev Apr 04 '13 at 03:53
  • Okay thanks, just to clarify none of the paths refer to mapped drives, right? – Leigh Apr 04 '13 at 03:55
  • Yes, None of the paths refer to mapped drive. They all run in the local partition (D:). – Sanjeev Apr 04 '13 at 04:02

3 Answers3

4

I have found the answer to my problem.

I tried to go back to basics and check the issue from all the associated components.

  1. CF
  2. VB Script Code
  3. Word Application COM
  4. 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.

Sanjeev
  • 1,838
  • 1
  • 16
  • 28
0

I think your problems are related to windows ap vs console app. It might be that some parts require the console (windows desktop gui) to be active. There are services like for example DHCP that dont have dependencies there and thus run fine invisible as a pure service, without human interaction.

Perhaps just an idea try process monitor from sysinternals, it sometimes shows whats allowed and what is not allowed.

user613326
  • 2,140
  • 9
  • 34
  • 63
  • Thank you for the procmon idea. I shall try that – Sanjeev Apr 04 '13 at 03:55
  • if your app uses for example a file dialog screen then inmost cases it should be a console app and not a windows service app, in general people who write services for windows, create a separate tool to set settings in the registry and next restart their service to trigger reading reading from the registry. If your program isnt like that then dont use that. If you need a program just always be active then create a autostartup for each user (default user autostartup) user logon (notice that is not remote network logon), its for users who see the screen and sit behind it. – user613326 Apr 04 '13 at 18:06
  • There is another tool from systinternals called autoruns it gives you some ideas where you set things to autorun under windows..a lot places actually. – user613326 Apr 04 '13 at 18:07
  • Be aware that if you use a script while nobody is loged on the script cannot use things that depend from explorer.exe (file brouwsing stuff) Decide how it should work, as service? with no GUI interaction and dependencies (explorrer/ office). As a autostart when there is a user GUI logon As a normal application mabye or addon to office itself launched by Word or by the user. (or use a batch to launch before word) – user613326 Apr 04 '13 at 18:09
  • Thank you for the valuable comments. I shall consider all those scenarios while preparing the final system. – Sanjeev Apr 05 '13 at 01:58
0

It's also possible that there are some dialog boxes that are popping up. You may not be seeing these. You can try to disable these by setting Application.DisplayAlerts to false.

See How To Dismiss a Dialog Box Displayed by an Office Application with Visual Basic

Dharmendar Kumar 'DK'
  • 2,082
  • 17
  • 18
  • I have not observed any such prompts. I kept checking the Task manager all time. But, I do see a command prompt dialog box when I tick the 'Allow service to interact with desktop'. It shows nothing in it, and even with it, the conversion did not happen. – Sanjeev Apr 04 '13 at 02:43