none
Problem running Windows Service with Excel Object on Windows Server 2008 (64 bit)

    Question

  • 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
    Thursday, December 4, 2008 7:02 PM

All replies

  • Deleted
    Friday, January 9, 2009 8:09 AM
  • 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
    Friday, May 15, 2009 9:26 AM
  • 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
    Thursday, January 14, 2010 3:19 PM
  • 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
    Friday, March 12, 2010 4:58 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, April 28, 2010 8:44 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.

    Wednesday, January 11, 2012 1:36 PM
  • Hi Aeshwar,

     

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

     

    Thanks

    Johan

    Tuesday, January 31, 2012 8:04 AM
  • 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!
    Thursday, February 23, 2012 4:04 PM
  • 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

    Wednesday, June 6, 2012 11:23 PM
  • Thanks. It worked for me.

    Wednesday, July 18, 2012 5:42 AM
  • Thanks....

    Tuesday, July 31, 2012 5:37 AM
  • 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
    Thursday, November 29, 2012 9:15 PM
  • 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?

    Thursday, June 12, 2014 3:58 PM
  • 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 7, 2015 8:51 AM
    • Proposed as answer by Deepika K Thursday, May 5, 2016 9:13 PM
    • Unproposed as answer by Deepika K Thursday, May 5, 2016 9:13 PM
    Tuesday, April 7, 2015 8:37 AM
  • 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


    Debarchan Sarkar - MSFT ( This posting is provided AS IS with no warranties, and confers no rights.)

    Wednesday, April 8, 2015 7:53 AM
  • 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!



    • Proposed as answer by Deepika K Thursday, May 5, 2016 9:14 PM
    • Unproposed as answer by Deepika K Thursday, May 5, 2016 9:14 PM
    • Proposed as answer by Deepika K Thursday, May 5, 2016 9:15 PM
    • Unproposed as answer by Deepika K Thursday, May 5, 2016 9:15 PM
    Wednesday, July 8, 2015 2:15 PM
  • Hi, Did you get a solution for this issue ?
    Thursday, May 5, 2016 9:14 PM
  • Hi All

    I have created a small application that automates Excel via COM

    This runs fine when logged in and from a Windows 10 scheduled task in unattended mode when using Excel 2010

    However on another machine running Excel 2016 I cant get it to run in unattended mode at all (normal logged in mode is fine)

    It connects to the Excel application object but when I try and access the Workbooks collection to be able to open a document it just says the Excel object is not initialised 

    I can't even get simple propeties of the application object like Name or ProductCode

    As I say all is fine in attended mode so the code must be OK

    Is anyone else automating the latest Excels in unattended mode via Task Scheduler ?

    Thanks

    Thursday, August 4, 2016 2:47 PM
  • Hi Minieggs,

    I have attempted to run excel macros via task scheduler and as a service.  LIke yourself I was able to get them to run properly while logged in (windows server 2012) but while the task and service still run while I am logged off, the excel portions are never executed.

    Did you by chance come by a solution to this problem?

    Thank you,

    -John

    Thursday, February 9, 2017 7:02 PM
  • The solution to create the folders was working for me fine until Windows build 1803.  My system auto updated yesterday, I created the folders (as I have to do after a new Windows build is installed), and my ability to call Word from a script no longer works.   Argh!!!  Anyone else have other possible solutions?  Thanks!
    Thursday, June 14, 2018 4:04 PM