Jacob Not working when running as service on Windows 2008 (win7)

本文探讨了Jacob在Windows Vista、7及2008 Server环境下作为服务运行时遇到的问题,尤其是在启动Word.Application组件时发生的错误。同样的代码在Windows XP和2003上则能正常工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值