Question

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:

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.

Any suggestions?

Was it helpful?

Solution

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.

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.

OTHER TIPS

A guy named "Gary McGill" has posted a solution that worked very well for me (on a question that is quite similar):

Automating Office via Windows Service on Server 2008

works like a charm (and I didn't even have to check the "Allow service to interact with desktop" checkbox on the "Log On" tab)

  • Go into the Component Services>Computer>My Computer>DCOM Config.
  • Go to the 'Microsoft PowerPoint Slide' DCOM and select properties.
  • Go to the identity tab and change the user from being inherited to be a specific user with Network Service/access priveleges.

PowerPoint interop shouldn't try and open UI but that may be the problem too.

Try to set the Service to interact with the Desktop.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top