I am facing a situation here and would like some feedback or advice.
I have been given an application that run as a service, with a specific service account (not admin on the server), and try to open an Excel workbook.
The problem is not with the initial application, as I can reproduce it with the generic C# code below (embedded in a service structure):
try{
this._exApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
this._exApp.Visible = false;
Log.Logger.Info("Opening workbook...");
Workbook workbook = this._exApp.Workbooks.Open(
thisFileName,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing
);
Log.Logger.Info("Workbook opened!");
//Do something with the result
Log.Logger.Info("Closing workbook...");
workbook.Close(false, thisFileName, null);
Marshal.ReleaseComObject(workbook);
this._exApp.Quit();
}
catch(Exception ex){
Log.Logger.Error(ex.Message);
}
(nothing special about *this._exApp* and thisFileName, which are just respectively casted to a Microsoft.Office.Interop.Excel.Application, and as a string with the path of the file to open. Log.Logger is a a logger class using log4net to allow me seeing when the problem occurs)
The service is running as a service account, which is a user on the server, not an admin. It has access to the target file and to files on the server (as Read access). The server is a Windows Server 2003 Standard Edition SP2 (could not try yet on a 2008 R2 server).
The problem I am facing is that it just hangs when trying to open the workbook, so in terms of tracing the last line I have is “Opening workbook…”, never reaching the “Workbook opened” line. No exception is raised.
So the code is very simple, it is just trying to open an excel workbook. I have done already some investigations, and here are my findings:
- I know that Microsoft does not support a server side Excel automation, but I have been given the service as it, and do not have a choice about the technology used.
- I have configured all the Component Services/DCOM/Microsoft Excel Application security settings so that the service account has all the permissions possible.
- The service does the job correctly if the service account is local admin on the machine. This is not really on option for production.
- The service does the job correctly if the file it tries to open is a local file. Unfortunately, the file we tries to access is on a remote file server, and it does not work in that situation.
- The code above run from a command line with the same user on a remote file works fine, but not any more when run as a service.
- I have read about the C:\Windows\System32\config\systemprofile\Desktop bug, but the folder exists.
- Excel open correctly when lauched with the service account.
So basically, the situation is the Workbooks.Open method hangs when run as a service, under a service account that is not admin, and when accessing a remote file.
I would appreciate any input or idea on this topic.
Thanks.
Jonathan
EDIT: As per Matt’s workaround below, we have implemented a local copy of the remote file, so I am accepting it as an answer, but I remain interested in any suggestion on how to make it work directly on the remote file.
I would have put this as a comment, but I don’t have enough rep yet, so this is more just a possible workaround rather than a full blown answer…
Can you first copy the file from the remote server to a local temp location?