导航

Windows Service 中访问Excel对象时拒绝访问

Posted on 2011-03-25 17:44  Conia  阅读(687)  评论(0)    收藏  举报

环境:Win2008R2, Excel2010

c# 写的Windows service,本地直接跑,一切正常,发布安装后,log中提示

System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Excel cannot access the file .
There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.

解决方法:

1. 任务管理器中关闭所有Excel进程
2. 打开组件服务,cmd中敲dcomcnfg
3. 依次展开 控制台根节点--组件服务--计算机--我的电脑--DCOM配置,找到Microsoft Excel Application
4. 右键属性-标示 选择运行此应用程序的帐户中选中“交互式用户”,确定

-------------------------------------------------------

有人说建文件夹即可,不过我的环境下试了没用

・Windows 2008 Server x64
C:\Windows\SysWOW64\config\systemprofile\Desktop

・Windows 2008 Server x86
C:\Windows\System32\config\systemprofile\Desktop
-------------------------------------------------------------

From:http://bytes.com/topic/c-sharp/answers/819740-c-service-excel-application-workbooks-open-fails-when-called-service