Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Excel cannot access the file "...". There are several possible reasons Windows Server 2008 R2 with Microsoft Office 2010

Tags:

c#

excel

I have a problem with starting the Excel Application under a particular user.

I try to schedule this script (C#) through an application X (not Windows Task Scheduler. And this application will always use a service account to run services on the server). If I run the C# script in command prompt under the same user, it runs. Under the application X, which uses the exact same user, to initiate the C# script, it fails to open the Excel application (not sufficient permission?).

This script calls: app.Workbooks.Open(ExcelFileName,0,false,Type.missing....), yet it gives the following error:

Microsoft Excel cannot access the file "...". 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.

I tried all the methods that I found online to no avail.

  1. Create directory “C:\Windows\SysWOW64\config\systemprofile\Desktop” (for 64 bit Windows) or “C:\Windows\System32\config\systemprofile\Desktop” (for 32 bit Windows). Then Set full control permissions on Desktop directory above (for example in Win7 & IIS 7 & DefaultAppPool set permissions for user “IIS AppPool\DefaultAppPool”)
  2. Changed the DCOM config for the Microsoft Excel application to include this user for Local/Remote Launch and Access
  3. Enabled all macros in Excel and set the Trust Center.
  4. Add the user to have full control on all folders that contain the Excel file.
  5. Under DCOM config, Microsoft Excel Application, if I modify the Identity tab to check on "This User" and enter the username/password to let Excel always run under that user. Then the application runs perfectly. However, other users can't run the excel application on their own with the following error: "Cannot use object linking and embedding". If I check "Use the launching user", then Excel can't be launched. No errors in the logs or events anywhere to check.

Yet, still the same error. I think it's permission but I am not sure where and what to do for this to work.

Now, normally, when I run this excel report, I can double-click on the file and it'd automatically run, save the new parameters into the current file and generate a new excel file (with date attached to the file name). That means there is a change (save) to the original file.

I appreciate all your help!

like image 293
ntumi Avatar asked Dec 08 '22 04:12

ntumi


1 Answers

I found the problem is the layer of security in the server!

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.

This works!

like image 133
ntumi Avatar answered Dec 10 '22 18:12

ntumi