none
Possible Permissions Issue with Workbooks.OpenText RRS feed

  • Question

  • We have a .net console app that attempts to open a text file via Excel interop automation.

    XL.Workbooks.OpenText(@TempFile, Type.Missing, 1, Excel.XlTextParsingType.xlDelimited, Excel.XlTextQualifier.xlTextQualifierDoubleQuote, false, false, false, false, false, true, "|");                 XL.Workbooks[1].Activate();                 

    XL.Workbooks["Temp.txt"].SaveAs(OutputFile, Excel.XlFileFormat.xlOpenXMLWorkbook);                 XL.Workbooks[ExcelFilename].Close();                 XL.Quit();


    This code runs fine when the console is run standalone.  However, when we run the console app via the Windows Task Scheduler, the OpenText call fails with the following error:

    System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Excel cannot access the file 'C:\CustomerEmails\Temp.txt'. 

    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.
       at Microsoft.Office.Interop.Excel.Workbooks.OpenText(String Filename, Object Origin, Object StartRow, Object DataType, XlTextQualifier TextQualifier, Object ConsecutiveDelimiter, Object Tab, Object Semicolon, Object Comma, Object Space, Object Other, Object OtherChar, Object FieldInfo, Object TextVisualLayout, Object DecimalSeparator, Object ThousandsSeparator, Object TrailingMinusNumbers, Object Local)
       at Utils.Data.CustomerEmailsReport(SqlConnection Conn, String ReportName, String StoredProcedure) in 

    Note, the file does exist and 

    the userid that the task is run under is in the local admin group and is run with the highest privileges.  Is there some kind of security policy that might affect the opening of a local file via the task scheduler?



    • Edited by scott_m Monday, August 14, 2017 9:26 PM
    Monday, August 14, 2017 9:24 PM

Answers

  • Hi scott_m,

    are you trying to run this app on server?

    it maybe a problem with permissions.

    I try to find the details regarding the issue.

    I find one thread in which other user had a same issue like yours.

    below is the steps how he solved his issue.

    Creating the Desktop folder inside the C:\Windows\System32\config\systemprofile and giving the service account permission to access the desktop folder is not enough.
    
     I modified the C:\Windows\System32\config (or C:\windows\SysWOW64\config) folder to allow permission to the service account in security tab.
    
     Then I also had to set up the same permission for the sub folder C:\Windows\System32\config\systemprofile (or C:\windows\SysWOW64\config\systemprofile) for the service account.
    

    Reference:

    Microsoft Excel cannot access the file

    let me know , if you have the same situation like that or you are trying to run this project on local machine.

    so that I can try to provide you further suggestion to solve the issue.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by scott_m Tuesday, August 15, 2017 3:00 PM
    Tuesday, August 15, 2017 2:44 AM
    Moderator
  • Thanks Deepak

    This post also has a good discussion on the issue / solution.

    https://superuser.com/questions/579900/why-cant-excel-open-a-file-when-run-from-task-scheduler

    • Marked as answer by scott_m Tuesday, August 15, 2017 3:00 PM
    Tuesday, August 15, 2017 3:00 PM

All replies

  • Hi scott_m,

    are you trying to run this app on server?

    it maybe a problem with permissions.

    I try to find the details regarding the issue.

    I find one thread in which other user had a same issue like yours.

    below is the steps how he solved his issue.

    Creating the Desktop folder inside the C:\Windows\System32\config\systemprofile and giving the service account permission to access the desktop folder is not enough.
    
     I modified the C:\Windows\System32\config (or C:\windows\SysWOW64\config) folder to allow permission to the service account in security tab.
    
     Then I also had to set up the same permission for the sub folder C:\Windows\System32\config\systemprofile (or C:\windows\SysWOW64\config\systemprofile) for the service account.
    

    Reference:

    Microsoft Excel cannot access the file

    let me know , if you have the same situation like that or you are trying to run this project on local machine.

    so that I can try to provide you further suggestion to solve the issue.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by scott_m Tuesday, August 15, 2017 3:00 PM
    Tuesday, August 15, 2017 2:44 AM
    Moderator
  • Thanks Deepak

    This post also has a good discussion on the issue / solution.

    https://superuser.com/questions/579900/why-cant-excel-open-a-file-when-run-from-task-scheduler

    • Marked as answer by scott_m Tuesday, August 15, 2017 3:00 PM
    Tuesday, August 15, 2017 3:00 PM