Powerpoint Interop在Windows Service中失败,但在Windows Form应用程序中工作正常 [英] Powerpoint Interop fails in a Windows Service but works fine in a Windows Form application

查看:97
本文介绍了Powerpoint Interop在Windows Service中失败,但在Windows Form应用程序中工作正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个用于监视文件夹的应用程序,每当将PowerPoint文档放入其中时,它都会浏览其中的幻灯片并为每张幻灯片生成png图像.在Windows窗体应用程序中这可以正常工作,但是我已经将完全相同的代码放在Windows服务中,使用了相同的测试文件,但由于以下错误而无法将其打开:

I've written an application to watch a folder, and whenever a PowerPoint document is dropped into it, it goes through the slides within it and generates png images of each slide. This works fine in a windows forms application but I've put exactly the same code in a windows service, used the same test file and it fails to open it with the following error:

错误:PowerPoint无法打开文件. 在Microsoft.Office.Interop.PowerPoint.Presentations.Open(字符串FileName,MsoTriState ReadOnly,MsoTriState无标题,MsoTriState WithWindow)-2147467259 Com Error

Error: PowerPoint could not open the file. at Microsoft.Office.Interop.PowerPoint.Presentations.Open(String FileName, MsoTriState ReadOnly, MsoTriState Untitled, MsoTriState WithWindow) -2147467259 Com Error

我已将服务设置为使用自己的用户帐户(具有管理员权限)运行,因此我认为这可以排除权限问题,但我认为没有其他尝试方法.

I've set the service to run with my own user account (with Administrator privileges) so I think that would rule out permissions problems but I can't think of anything else to try.

有什么建议吗?

推荐答案

如果没有很多信息,就无法说出问题所在.可能有很多东西.如果操作系统是XP或更早版本,则在运行服务时将不会加载用户的配置文件,因此PP可能无法访问其所需的某些信息. PP可能正在尝试一些复杂的操作(假设它处于交互式会话中).由于缺少用户配置文件,PP使用的COM组件可能无法初始化.真正的错误甚至可能不是安全问题,对于开发人员而言,使用ERROR_ACCESS_DENIED或ERROR_OUT_OF_MEMORY作为捕获所有意外错误的情况并不少见.

There is no way to tell what the problem is without a lot more information. It could be any number of things. If the OS is XP or earlier then the user's profile will not be loaded when the service runs so PP may not be able to access some information it needs. PP could be attempting some complex operation that assumes it is in an interactive session. A COM component that PP uses might not be able to initialize due to the lack of user profile. The real error may not even be a security issue, it is not uncommon for developers to use either ERROR_ACCESS_DENIED or ERROR_OUT_OF_MEMORY as a catch all for unexpected errors.

但是真正的问题是PowerPoint很大程度上是用户的土地申请-不应在服务中使用它.将服务设置为与桌面交互是一个不好的解决方案.即使它确实起作用,也将掩盖更深层次的问题,并使它作为服务运行在某种程度上毫无意义.有许多实用程序和组件可用于将PowerPoint幻灯片转换为图像文件.在Google上进行的快速搜索会返回许多可能性,这些可能性看起来更适合用于服务中,并且其中大多数都是相当便宜的.

But the real issue is that PowerPoint is very much a user land application - it shouldn't be used in a service. Setting the service to interact with the desktop is a bad solution. Even if it does work, it will just be masking a deeper problem, as well as making it somewhat pointless to run it as a service. There are a number of utilities and components that can be used to convert PowerPoint slides to image files. A quick search on Google returns many possibilities that look to be much more suitable for use in a service and most of them are quite cheap.

这篇关于Powerpoint Interop在Windows Service中失败,但在Windows Form应用程序中工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆