views:

688

answers:

3

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?

A: 

Try to set the Service to interact with the Desktop.

ofer
I tried this and got a different error: "COM object that has been separated from its underlying RCW cannot be used" which I think is to do with me testing the service in Vista (http://www.microsoft.com/whdc/system/vista/services.mspx)
breathingdust
A: 

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.

Stephen Martin
I had evaluated a few components, but they suffered from pptx incompatibility and/or would occasionally be unable to process the odd file. Interop managed to get through 100% of the 3-400 files I tested it with.
breathingdust
I think you're right though, Microsoft themselves don't recommend this approach (http://support.microsoft.com/default.aspx?scid=kb;en-us;257757), I think stability is preferable to not being able to process the occasional file. Will be using Aspose.Slides instead, which will support pptx in future.
breathingdust
A: 

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

http://stackoverflow.com/questions/1006923/automating-office-via-windows-service-on-server-2008/1680214#1680214

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)

Zurb