mue*_*uek 8 c# scheduled-tasks excel-interop windows-server-2008
我在C#.NET中开发了一个使用Excel Interop的控制台程序.如果我从命令行运行它,该程序在我的开发机器和Windows Server 2008中运行正常.
当我尝试安排每天运行它的任务时,我得到了令人讨厌的Interop错误:
02/11/2011 00:30:05,000 [1] FATAL My.Program [(null)] - Unable to Microsoft Office Excel open file 'E:\excel.xls' by one of several 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 the currently opened book.
System.Runtime.InteropServices.COMException (0x800A03EC): Unable to access the Microsoft Office Excel file 'E:\excel.xls' by one of several 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 the currently opened book.
in Microsoft.Office.Interop.Excel.Workbooks.Open (String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, IgnoreReadOnlyRecommended Object, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
Run Code Online (Sandbox Code Playgroud)
文件'e:\ excel.xls'存在,如果在程序启动时完全关闭,因为如果我尝试在命令行中运行相同的程序,它会按预期结束.
我还设置我的任务以管理员身份运行,因此它不应该是权限问题.
你能帮助我吗?
简而言之,请确保为任务计划程序中使用的配置文件创建具有适当权限的文件夹,这不是只读的:
C:\Windows\System32\config\systemprofile\Desktop C:\Windows\SysWOW64\config\systemprofile\Desktop
并检查这个:
从“开始”菜单中,单击“运行”并键入 Dcomcnfg.exe。在组件服务中,单击控制台根目录,展开组件服务,展开计算机,展开我的电脑,展开 DCOMConfig。搜索 Microsoft Word 14.0 对象库。点击它。右键单击并选择属性。在安全选项卡上,在“启动和激活”部分中选择自定义。单击编辑并添加应用程序在其下运行的应用程序池的标识。对“访问权限”重复上述步骤
当您通过计划任务执行办公自动化时,事情可能会变得有点奇怪,因此我建议尝试不同的用户帐户。
如果它在您登录时有效,那么我建议设置任务计划程序以在您的帐户下运行它。如果仍然有效,请创建一个具有与您的帐户相同权限的新帐户,并让它在该帐户下运行。
否则,请尝试以管理员帐户身份登录,并确保应用程序在以管理员身份登录时运行。例如,可能有一些 Office 会在用户首次交互式登录或类似情况下进行设置。
| 归档时间: |
|
| 查看次数: |
8773 次 |
| 最近记录: |