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
Jacob Not working when running as service on Windows 2008 (win7)
最新推荐文章于 2022-08-03 16:30:50 发布