我收到错误消息:
System.Runtime.InteropServices.COMException (0x80080005):检索具有 CLSID {91493441-5A91-11CF-8700-00AA0060263B} 的组件的 COM 类工厂失败,原因是以下错误:80080005。
用于线PowerPoint.Application PowerPoint_App = new PowerPoint.Application();
对于这里的代码块:
using (new Impersonator(Installs.Current.PPTUser, null, Installs.Current.PPTPassword))
{
PowerPoint.Application PowerPoint_App = new PowerPoint.Application();
PowerPoint.Presentation presentation = null;
try
{
PowerPoint_App.Visible = MsoTriState.msoTrue;
presentation = PowerPoint_App.Presentations.Open(
strPptFilePath, Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoTrue);
for (int i = 0; i < presentation.Slides.Count; i++)
{
readSlides(presentation, i);
}
presentation.Close();
PowerPoint_App.Quit();
}
catch (Exception ex)
{
strSuccess = ex.ToString();
MindMatrix.Libraries.Entities.ExceptionMessage.HandleException(ex, null);
}
finally
{
Marshal.FinalReleaseComObject(presentation);
Marshal.FinalReleaseComObject(PowerPoint_App);
}
}
每当我第一次运行代码时,它都能完美运行,但随后它会为 PowerPoint 创建进程(可以在任务管理器中看到)。我曾经PowerPoint_App.Quit();
退出已经打开的进程,但它不起作用并抛出错误。我去任务管理器并从那里结束进程,然后它准备好再工作一次。
从代码中退出进程时我做错了什么还是有其他方法可以做到这一点?