Can't schedule Program with Excel Interop
Asked Answered
R

7

13

I have developed a console program in C# .NET, that uses Excel Interop. The program works just fine on my development machine and in the windows server 2008, if I run it from command line.

When I try to schedule a task to run it daily, I got this annoying Interop error:

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) 

The file 'e:\excel.xls' exists and if completely closed when the program starts, because if I try to run the same program in my command line, it ended as expected.

I also have setup my task to run as Administrator, so it shouldn't be permissions issues.

Can you help me?

Riker answered 11/2, 2011 at 20:53 Comment(1)
did you figure out the solution or work around for this problem? I have exactly same issue, can you please post your solution? Thanks!Clytemnestra
P
1

Things can get a bit weird when you do Office Automation from a scheduled task, so I'd suggest trying a different user account.

If it works when you're logged in, then I'd suggest setting up the task scheduler to run it under your account. If that still works, then create a new account with the same kind of permissions as your account and have it run under that account.

Otherwise, try logging on as the administrator account and make sure that the app runs when logged in as administrator. For example, maybe there is some bit of Office that gets setup during the first interactive login by the user or similar.

Pamulapan answered 11/2, 2011 at 21:8 Comment(4)
As I said, I already setup schedule task to run as AdministratorRiker
@muek: That's not a response to my answer though, unless Administrator is the account which you normally log in as? My answer is not so much about permissions as it's about if everything is setup the same under both accounts.Pamulapan
The aacount that I run using console or schedule is the sameRiker
@muek: Ok, then I don't know what the cause could be I'm afraid.Pamulapan
B
23

Check this out. Looks like you have to create a folder to get this thing to work right.

C:\Windows\System32\config\systemprofile\Desktop

Taken from this article here

http://social.msdn.microsoft.com/Forums/en/innovateonoffice/thread/b81a3c4e-62db-488b-af06-44421818ef91

Burly answered 17/4, 2012 at 21:47 Comment(3)
Excellent! This solved my issue straight away. I'm scheduling a C# application.Michelmichelangelo
This solved my issue along with checking the "Run with highest privileges" checkbox in the scheduled task properties.Rigger
Worked for me as well. For reference, my setup is: Windows 7, Excel 2010 and 2013 installed, and Scheduled Task with "run with highest privileges" turned on as well as Configure for: "Windows 7, Windows Server 2008 R2".Leticia
K
6

In short make sure to create these folders with appropriate rights for the profile used in the task scheduler and that folder is is NOT SET as readonly:

C:\Windows\System32\config\systemprofile\Desktop C:\Windows\SysWOW64\config\systemprofile\Desktop

And check this if doesn't work:

From the Start menu, click Run and type Dcomcnfg.exe. In Component Services, click Console root, expand Component Services, expand Computers, expand My computer,expand DCOMConfig. Search for relevant app, such as Microsoft Word 14.0 Object Library. Click on it. Right click and select Properties. On security tab, select Customize in "Launch and Activation" section. Click edit and add identity of app pool under which you application is running. Repeat above step for "Access Permission"

Kilburn answered 5/10, 2016 at 10:8 Comment(0)
I
3

Create a directory “Desktop” under:

“C:\windows\system32\config\systemprofile\Desktop”

AND

“C:\windows\SysWow64\config\systemprofile\Desktop” for 64 bit operating systems

Grant full access to this folder for the user running the service. It should solve your problem.

Interstitial answered 26/10, 2018 at 9:40 Comment(0)
P
1

Things can get a bit weird when you do Office Automation from a scheduled task, so I'd suggest trying a different user account.

If it works when you're logged in, then I'd suggest setting up the task scheduler to run it under your account. If that still works, then create a new account with the same kind of permissions as your account and have it run under that account.

Otherwise, try logging on as the administrator account and make sure that the app runs when logged in as administrator. For example, maybe there is some bit of Office that gets setup during the first interactive login by the user or similar.

Pamulapan answered 11/2, 2011 at 21:8 Comment(4)
As I said, I already setup schedule task to run as AdministratorRiker
@muek: That's not a response to my answer though, unless Administrator is the account which you normally log in as? My answer is not so much about permissions as it's about if everything is setup the same under both accounts.Pamulapan
The aacount that I run using console or schedule is the sameRiker
@muek: Ok, then I don't know what the cause could be I'm afraid.Pamulapan
G
1

The file 'e:\excel.xls' exists

It doesn't. Mapped drive letters like E: are per-user. The drive is valid only under your user account, the scheduled task is probably running using another account. Instead of tinkering with accounts, the best thing to do is to use a universal name. Like \\server\share\excel.xls, that's valid for any account. Ask more questions about it at serverfault.com

Garate answered 11/2, 2011 at 21:33 Comment(1)
The file exists. E: drive is not a mapped drive, it's a real oneRiker
N
0

I was struggling to get this to work. I had been all over google, I thought that I had solved my problem with help of one thread that had a drop down while setting up the scheduled task that allowed you to select XP as the "Configure for" option, the XP option is only available when creating the task from the beginning. That worked fine as long as the owner of the scheduled task was actually logged into the machine.

I finally was able to correct it in the DCOM config by adjusting the Identity and hard coding a user to the panel.

Necking answered 23/9, 2013 at 11:54 Comment(0)
N
0

For me it was the user under which I was running the task. It was failing for a domain user even if it was an Administrator. I switched the user to local machine's "Administrators" group and the error was gone.

Nomination answered 12/3, 2024 at 12:37 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.