C# – File Access from Excel COM object fails when run from NT Service on Vista

ccomnetvbscriptwindows-vista

We use COM objects to access excel spreadsheets in an NT service (via the Windows Scripting Host). Prior to Vista, this worked beautifully, but starting with Vista, we receive this error:

Microsoft Office Excel cannot access the file 'c:\myfiles\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.

I have tried changing the NT service logon settings to use my own account, an admin account and local system. I've looked through the Local Security Policy and have not found anything. I've spent days searching through the Microsoft KB to no avail.

If the script is executed from a console application, it works fine. The file opens and is processed with no problem. The error only occurs when executed from within the context of a service.

If the service is running on Windows XP or Server 2003 SP1, it also works fine. Only on Vista does it fail (and we've now gotten reports of it failing in Server 2003 SP2)!

The code, for what it is worth is exceptionally simple:

dim xl_app
Set xl_app = CreateObject("Excel.Application")
xl_app.Workbooks.Open mypath,0,1

I suspect that this person might be experiencing the same issue:
http://bytes.com/forum/thread819740.html

Best Answer

just some further questions:

  • Which version of Excel are you using?
  • Have you tried running the service with elevated privileges?
Related Topic