#86 Not working when running as service on Windows 2008 (Vista)

1.15
open
nobody
Jacob COM (35)
9
2009-10-29
2009-10-29
Rm.
No

Jacob is not working when running as service on Windows Vista, Windows 7 and Windows 2008 server. Same code works fine on Windows XP and Windows 2003 server.

Following source code won't work when started as Windows 2008 (Vista, 7) service:

01. ActiveXComponent word = new ActiveXComponent("Word.Application");
02. Dispatch wordObject = word.getObject();
03. Dispatch documents = word.getProperty("Documents").toDispatch();
04. word.setProperty("Visible", new Variant(false));
05. Dispatch document = Dispatch.call(documents, "Open", "c:\\template.doc").toDispatch(); // VariantChangeType failed

Error will occur on line 5 of the source code above, stack trace is:
com.jacob.com.ComFailException: VariantChangeType failed
at com.jacob.com.Variant.toVariantDispatch(Native Method)
at com.jacob.com.Variant.toDispatch(Variant.java:1996)

Same source code will work when running as service on XP, 2003 or when running as classical process application (not as service). This problem occurs for instance when this is in web application running as Tomcat service on Windows 2008.

I wrote very simple application to demonstrate this behavior and I included all necessary scripts to install it as Windows service (using instsrv and srvany). You just have to extract attached zip into C:\jacobService.

1) extract attached zip into C:\jacobService
2) run c:\jacobService\scripts\installService.bat to install example application as Windows service
3) run c:\jacobService\scripts\startService.bat to run installed service
4) look at c:\jacobService\jacobService.txt - if running on Windows XP its ok and file templateDone.doc is created on c:\jacobService. if running on Windows 2008 this will fail with following output:

Starting ... Thu Oct 29 17:12:33 CET 2009, path C:\jacobService
1
2
3
4
ERROR VariantChangeType failed
com.jacob.com.ComFailException: VariantChangeType failed
at com.jacob.com.Variant.toVariantDispatch(Native Method)
at com.jacob.com.Variant.toDispatch(Variant.java:1996)
at cz.zdenekhorak.jacob.JacobServiceTest.main(JacobServiceTest.java:23)
DONE.

I think this is very serious problem - JACOB is then quite unusable in web applications running on newer Windows server systems like Windows 2008 server.

Thanks for the fix.

Discussion

  • Rm.

    Rm. - 2009-10-29

    example application and source codes

     
  • Rm.

    Rm. - 2009-10-29
    • priority: 5 --> 9
     
  • Rm.

    Rm. - 2010-03-05

    I figured out workaround to this problem. Obviously Windows Vista and 2008 changed its behavior to COM objects in non-interactive mode. You can use DCOMCNFG to set an interactive identity for your COM objects. Use this: http://msdn.microsoft.com/en-us/library/ms678426\(VS.85).aspx#setting_the_identity_for_an_application and set identity of (for example Office COM objects) to interactive. Everything will work as on Windows XP and lower than.

     
  • clay_shooter

    clay_shooter - 2010-11-08

    You may have to look at the server automation guidlines on the microsoft site. I believe that they tell you what you need to do to run Office applications from a service.

     
  • lvqing

    lvqing - 2011-11-06

    The problem solved?????

     
  • Romain ROLLAND

    Romain ROLLAND - 2012-02-15

    I have the same problem, have you find how to solve this ?

     
  • Rm.

    Rm. - 2012-02-15

    @mhtagada: Yes Romain, see my first comment. You have to execute DCOMCNFG and set your components to operate in interactive mode for your COM objects. It's an operation system thing, you have to set this up on OS greater than XP when you're executing this as Windows Service. See the link in my first comment for more details.

     
  • Romain ROLLAND

    Romain ROLLAND - 2012-02-15

    @zdenekhorak : yes I have see your comment and try but I can't find Office COM objects, using word2010

     
  • Rm.

    Rm. - 2012-02-15

    @mhtagada: The name of this DCOM may be very confusing, it really depends on system locales, service packs etc. The name might even be something like"Documents", "{08655947-3AD4-4A46-8381-29BD55FEEEE9}", ... really anything.
    Try to find the name for your Word DCOM: http://forums.asp.net/t/1110648.aspx/1

     
  • Romain ROLLAND

    Romain ROLLAND - 2012-02-17

    ok I have find the word AppId but there isn't DCOM with this name

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks