简体   繁体   中英

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?

You did not clarify that the file: "D:\Automation\02_14_25_.xlsx"

Actually exists or if that is just the error message you could not correctly interpret.

In that case my answer would be: Your application is not started with the correct environment variables if it runs as a scheduled task. That is my classical mistake for the:

"It works when i run it manually but it doesn't when i do it with cron/scheduled task." - Scenario

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM