none
Excel Automation with Interop - Windows Service - Microsoft Excel cannot access the file RRS feed

  • Question

  • I have a windows console application, which automates Excel. In our scenario the application gets called from a Windows Service. If the console app is executed directly everything works fine. If the console app is executed through the Win Service, we get the following error when trying to open the excel file:

    Unhandled exception Occured : 'Microsoft Excel cannot access the file 'bla.xls'. 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.'.'

    The code snippet used to open the file:

    xlApp = new Application();

    xlApp.Visible = false;

    xlApp.UserControl = false;

    xlApp.Application.ScreenUpdating = false;

    xlApp.DisplayAlerts = false;

    xlWorkbook = xlApp.Workbooks.Open(

    Filename: filePath, 

    UpdateLinks: 2, 

    IgnoreReadOnlyRecommended: true,

    Editable: false);

    The console app and windows service are running on a Win Server 2008 64-bit OS with Excel 2013 32-bit installed. The service is running with a special user account, which has all the right permissions on accessed files and folders. The excel process is also started with the same account (I cheched that one). 

    I already tried to do the following, but to no avail:

    Run excel.exe /automation -> worked fine

    Created the folders and also gave full control to the account under which the service is run (even gave full control to Everyone)

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

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

    Configured DCOM

    Excel Application -> Identity -> Specific user account

    Excel Application -> Identity -> Interactive User

    Excel Application -> Security -> Launch permissions -> Everyone full control

    Several combinations of the above

    So I really am stuck with this problem right now. Any input on this is appreciated.

    Tuesday, March 3, 2015 6:06 PM

Answers

  • I have a windows console application, which automates Excel. In our scenario the application gets called from a Windows Service. If the console app is executed directly everything works fine. If the console app is executed through the Win Service, we get the following error when trying to open the excel file

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

    You can read more about that in the Considerations for server-side Automation of Office article.

    Tuesday, March 3, 2015 7:08 PM