Problem running Windows Service with Excel Object on Windows Server 2008 (64 bit)
I am using Microsoft Office 11.0 Object Library. The code runs fine on Windows Server 2003.

Below is the code sample.

============================================================================ using Microsoft.Office.Interop.Excel; using Excel = Microsoft.Office.Interop.Excel; using System.Runtime.InteropServices;

Excel.Application m_ExcelApplication = new Excel.Application(); m_ExcelApplication.Visible = false; m_ExcelApplication.UserControl = false; m_ExcelApplication.Application.ScreenUpdating = false; m_ExcelApplication.DisplayAlerts = false; string strFileName = @"d:\testing\testing.xls";
Excel.Workbook m_ExcelWorkBook = m_ExcelApplication.Workbooks.Open(strFileName, //FileName 2, //UpdateLinks bReadOnly, //ReadOnly Type.Missing, //Format Type.Missing, //Password Type.Missing, //WriteResPassword true, //IgnoreReadOnlyRecommended Type.Missing, //Origin Type.Missing, //Delimiter false, //Editable Type.Missing, //Notify Type.Missing, //Converter Type.Missing, //AddToMru Type.Missing, //Local Type.Missing //CurruptLoad );
===============================================================================
When executing the Open function. I received the following exception:
Microsoft Office Excel cannot access the file 'd:\testing\testing.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.
However, when I removed the directory information and just give it the file name: 'testing.xls' - I putted testing.xls in to the same directory as the Windows Service- everything works fine.
Please help.
Any help will be greatly appreciated.
Thanks
December 4th, 2008 7:02pm

Wondering if you have solved this issue yet.

Research shows that automation is an issue with Windows Server 2008, specifically the 64-bit version. The 32bit version works, as well as windows 2003 32/64bit. I'm unsure as to whether it affects only SERVICES or APPLICATION automation as well.. We use a service for our tasks.

Recently we have run into this problem, and it's pretty important. We do some high dollar work using excel automation, and have recently obtained a new system running windows server 2008, just to find out there seems to be a bug/issue that prevents our application from doing its core work.

If you have found a solution please let me know.
Free Windows Admin Tool Kit Click here and download it now
January 9th, 2009 8:09am

Hi, I was also looking for a solution to this.. and I was able to come up with a "hack" to make it work.

It seems that even if you impersonate the service, or assign a specific user to it, or impersonate Excel with DCOM, when the Excel object is instantiated it still uses the Local System as its security profile. Because of this, it uses the registry hive of the Local System and it ends up with properties like StartupPath = "C:\windows\system32\config\systemprofile\AppData\Roaming\Microsoft\Excel\XLSTART", etc..

Now, open up REGEDIT and navigate to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-18\ProfileImagePath and make a backup of its value. Next from within the ProfileList registry hive, locate a valid desktop user profile (it should start with S-1-5-21-[xxxx]). Copy the value for its ProfileImagePath and overwrite the one assigned to the Local System profile. Restart your system before trying out the solution.

Note, however, that this is a "registry hack" and I discourage sticking to it. I'm still looking for an alternative solution, so please post your ideas here too if you have them.


HTH
-jeric


Update:

There is a better solution than the registry hack I mentioned above. It still involves fooling the system profile into acting like a user profile.

Please follow Ogawa's solution here: http://social.msdn.microsoft.com/Forums/en-US/innovateonoffice/thread/b81a3c4e-62db-488b-af06-44421818ef91?prof=required
  • Edited by angerico Monday, June 29, 2009 7:41 AM
May 15th, 2009 9:26am

i was have same problem too,
try your solution i still getting error..
iam  windows 7 and visual studio c# 2008
  • Proposed as answer by D2BII Friday, March 12, 2010 4:52 PM
Free Windows Admin Tool Kit Click here and download it now
January 14th, 2010 3:19pm

I thought I'd think out of the box a little and did this, which worked for the Excel.application object on a 64Bit Windows 2008 Server R2 and Windows 7 64Bit.

  1. Create a regular 32 bit VBS file that creates your Excel object doing whatever it is you need to do with it.
  2. Create a batch file that executes that file in a 32bit process.  Here's how:
  3. Create a filename (whatever) .bat
  4. Put the following in the .bat file - > C:\Windows\Syswow64\wscript.exe "C:\<path to your file>\<your filename>.vbs"  (or whatever drive or UNC path you need).  This tells Windows to run your script as a 32Bit process.
  5. Install MS Excel only with the absolute minimum of features.
  6. Run the batch file.
Wala!  CreateObject("Excel.Application") now works on 64Bit, but in 32bit mode.  Hope this helps.
  • Edited by D2BII Friday, March 12, 2010 5:00 PM greater clarity
March 12th, 2010 4:58pm

Can you give me more info on this .vbs file. I am trying to work on MS Excel Upload on a Win 2008 IIS7 server . From Visual Studio it works but when I deploy I started getting the errors. I tried Registry hack, no luck. The latest error I see is 

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.

Free Windows Admin Tool Kit Click here and download it now
April 28th, 2010 8:44pm

Hi,

What do you mean with "Now, open up REGEDIT and navigate to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-18\ProfileImagePath and make a backup of its value"? A backup, for what?

This is value we have to change, isnt it?

Thanks in advance,

Mónica.

January 11th, 2012 1:36pm

Hi Aeshwar,

 

Did you ever find a solution to this, i'm running the same spec as you Windows 2008 and IIS7.

 

Thanks

Johan

Free Windows Admin Tool Kit Click here and download it now
January 31st, 2012 8:04am

I've had the same problem for months.... and after ages of research I couldn't find an answer..... I solved the problem uninstalling Office 2007 and then installing Office 2003.... now it works perfectly!
February 23rd, 2012 4:04pm

Windows 2008 Server x64

  Please make this folder.

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

Windows 2008 Server x86

  Please make this folder.

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

Free Windows Admin Tool Kit Click here and download it now
June 6th, 2012 11:23pm

Thanks. It worked for me.

July 18th, 2012 5:42am

Thanks....

Free Windows Admin Tool Kit Click here and download it now
July 31st, 2012 5:37am

Thank you for the solution. This was the only thing I had to do for a 2008 Server x64.
  • Proposed as answer by Ganov Thursday, November 29, 2012 9:15 PM
November 29th, 2012 9:15pm

Hi,

We have Windows Server 2008 R2 64 bits and we are having the same problem... reading this blog i could not guess what was the solution some say to work :S

Can you help me?

Free Windows Admin Tool Kit Click here and download it now
June 12th, 2014 3:58pm

Can somebody please share the solution for this issue?

I am facing similar issue with Windows 2012 R2 x64 OS and Excel 2007(32-bit) combination.

I tried couple of things like Excel is able to Open an existing workbook on my system but fails to

create a new Workbook as done by invoking the "Add" command. It fails with Error 800a03ec.

I tried creating the two folders i.e. C:\Windows\SysWOW64\config\systemprofile\Desktop & C:\Windows\system32\config\systemprofile\Desktop, but could not get it working.


  • Edited by aksjain Tuesday, April 07, 2015 8:51 AM
April 7th, 2015 8:37am

Windows 2008 Server x64

  Please make this folder.

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

Windows 2008 Server x86

  Please make this folder.

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

Free Windows Admin Tool Kit Click here and download it now
April 8th, 2015 7:53am

Hello everyone,

I have the same problem under Server 2012 R2, but creating C:\Windows\SysWOW64\config\systemprofile\Desktop didn't help. I also checked the box "Run with highest Privileges".

Could anybody help me?

Thanks in advance!



July 8th, 2015 10:16am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics