Symptoms

If you run a program or script that uses the Excel API to manipulate an Excel workbook, your script or program may fail with the following error: 

 Script execution failed: Microsoft Office Excel cannot access the file 'C:\test\test.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. (1004) (Line 22, Column 0)

 This problem occurs when both of the following conditions are true:

  • You are running on Windows Vista, Windows Server 2008, or later; and
  • The adTempus job is running with the User Interaction set to "Hidden", or the job step is configured to run with the "Hidden" or "Capture Console" window mode.

Cause

First check to make sure the account you are running the job under has permission for the file named in the error message. If those permissions are correct, the failure is not caused by that file specifically.

Even though your script or program is executing under a user account, when Excel is launched through COM automation it is executed under the Local System user identity. This identity does not have a user profile, and this causes Excel to fail because it is designed to assume that it is running in an interactive user session.

The same automation approach works correctly under earlier versions of Windows because those versions enforced less strict isolation between logon sessions (see article K00000369 for more information on this change).

Resolution

A workaround has resolved this problem for many users. Create the following folders on the computer:

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

If the error still occurs, ensure that the account you are running the adTempus job under has Modify permission for the "systemprofile" folders and all subfolders.

If you continue to get the error, use the following procedure to determine what file(s) Excel is failing on:

  1. Download and run the Process Monitor tool from Microsoft.
  2. When Process Monitor starts, if the Filter window does not appear automatically, select Filter... from the Filter menu.
  3. In the Filter window, add a rule for "Process Name" "is" "excel.exe" then "Include".
  4. Add a second rule for "Result" "is" "ACCESS DENIED" then "Include".
  5. Add a third rule for "Operation" "is" "CreateFile" then "Include".
  6. Run the adTempus job.
  7. The Process Monitor log will show all the files and folders that Excel failed to access. Most of these can be ignored.
    • If the target Excel file is listed, then you have a problem with permission on that file.
    • If the "config" folder or a subfolder is listed, edit the permissions for the folder and give Modify permission for the account that the job runs under.

Additional Information

Excel and other Microsoft Office applications are not designed to be run as a "server" application, and Microsoft does not support this usage. See Microsoft knowledge base article 257757 for more information.

See this discussion in the Microsoft discussion forums for discussion of this issue and the workaround presented above.

Status

This problem is the result of design limitations in the Microsoft Excel product, and changes to user session isolation in Windows.