Problem running Windows Service with Excel Object on Windows Server 2008 (64 bit)
-
Thursday, December 04, 2008 7:02 PMI 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, //FileName2, //UpdateLinksbReadOnly, //ReadOnlyType.Missing, //FormatType.Missing, //PasswordType.Missing, //WriteResPasswordtrue, //IgnoreReadOnlyRecommendedType.Missing, //OriginType.Missing, //Delimiterfalse, //EditableType.Missing, //NotifyType.Missing, //ConverterType.Missing, //AddToMruType.Missing, //LocalType.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
All Replies
-
Friday, January 09, 2009 8:09 AMWondering 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.
-
Friday, May 15, 2009 9:26 AMHi, 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
-
Thursday, January 14, 2010 3:19 PM
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
-
Friday, March 12, 2010 4:58 PMI 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.
- Create a regular 32 bit VBS file that creates your Excel object doing whatever it is you need to do with it.
- Create a batch file that executes that file in a 32bit process. Here's how:
- Create a filename (whatever) .bat
- 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.
- Install MS Excel only with the absolute minimum of features.
- Run the batch file.
- Edited by D2BII Friday, March 12, 2010 5:00 PM greater clarity
-
Wednesday, April 28, 2010 8:44 PM
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.
-
Wednesday, January 11, 2012 1:36 PM
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.
-
Tuesday, January 31, 2012 8:04 AM
Hi Aeshwar,
Did you ever find a solution to this, i'm running the same spec as you Windows 2008 and IIS7.
Thanks
Johan
-
Thursday, February 23, 2012 4:04 PMI'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!

