首页 > 解决方案 > C# Win App, Task Scheduler, User Account: System. Microsoft Excel cannot access the file

问题描述

  1. Task Scheduler on a Windows server
  2. User Account is System
  3. Starts a .NET windows app that reads an Excel file
  4. Error:

Microsoft Excel cannot access the file 'D:\Automation\02_14_25_.xlsx' 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. I created the folder Desktop in C:\Windows\SysWOW64\config\systemprofile and C:\Windows\System32\config\systemprofile\ but still same error.
  2. When I log in to the server as myself(administrator) and run the app, it runs without errors. Any suggestions please?

标签: c#exceltaskscheduler

解决方案


您没有说明文件:“D:\Automation\02_14_25_.xlsx”

实际存在,或者这只是您无法正确解释的错误消息。

在这种情况下,我的回答是:如果您的应用程序作为计划任务运行,则它没有使用正确的环境变量启动。这是我的经典错误:

“当我手动运行它时它可以工作,但当我使用 cron/计划任务时它不起作用。” - 设想


推荐阅读