Excel自动化Workbooks.Open()函数通过Windows服务调用应用程序时会引发灾难性错误

我的一个应用程序是关于自动化MS Excel,同时创build一些graphics文件。 我正在使用基本的tli方法来实现这一点。 在xp机器上运行没有任何问题的代码已经开始给我这个问题,当我开始在windows7上做一些修改。发生什么如下所述:

引起问题的代码行围绕着:

if(!app.CreateDispatch("Excel.Application")) { fprintf(log, "%s\n", "Microsoft excel, could not be launched. Please make sure it is installed on the target machine."); return; } else { //Make the application visible and give the user control of //Microsoft Excel. //// app.put_Visible(TRUE); //// app.put_UserControl(TRUE); CString Title; CString s = app.get_Version(); //Excel 2003 takes 13 arguments hence we need to prepare options variant COleVariant covTrue((short)TRUE), covFalse((short)FALSE), covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR); CWorkbooks b=app.get_Workbooks(); CWorkbook bkThis, bkMaster; try { bkThis=b.Open(strFileName, covOptional, // UpdateLinks, covOptional, // ReadOnly, covOptional, // Format, covOptional, // Password, covOptional, // WriteResPassword, covTrue, // IgnoreReadOnlyRecommended, covOptional, // Origin, covOptional, // Delimiter, covOptional, // Editable, covOptional, // Notify, covOptional, // Converter, covOptional, // AddToMru, covOptional, // Local, covOptional // CorruptLoad, ); } catch(CException *e) { fprintf(log, "The input file being tried: %s\n", strFileName); fprintf(log, "%s(%d): OLE Execption caught: SCODE = %x",__FILE__, __LINE__, COleException::Process(e)); e->Delete(); app.Quit(); app.DetachDispatch(); app.ReleaseDispatch(); return; } 
  • 当我通过Visual Studio运行代码时,运行良好,但是当我使用Windows服务启动时,Workbooks.Open()函数失败,出现8000FFFF Catastrpic错误。
  • 安全特权不应该是问题,因为在调用此代码之前,我的ADO数据库连接正常。

请build议如果有人对此有任何想法。

问候YK