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?
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"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With