C# .NET - Window service throwing E_ACCESSDENIED error

Asked By Mitu N on 09-Jul-15 10:17 PM

Hi,

I've C# 4.0 windows service running on a Windows 2008 server. It uses MS Excel interop component to read and save excel files on the server. Its throwing following error while doing so:

Retrieving the COM class factory for component… error: 80070005 Access is denied.” (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

I checked the registry and I can see this class Id present over there. Not sure whats the solution for this issue.What permissions am I missing please?

I see following soln but I believe its for a app hosted in IIS? http://stackoverflow.com/questions/17785063/retrieving-the-com-class-factory-for-component-error-80070005-access-is-de

Thanks.

Robbe Morris replied to Mitu N on 10-Jul-15 10:49 AM
Could be a couple of things.  Do you have Office installed on the server where the service runs?
Does the service run under a Microsoft Windows account that has all the necessary priviledges? 

This "may" also be an issue with running user interface oriented software/objects under Windows Services.  That is typically not supported in Microsoft Windows.

I think spreadsheetgear.com has a component for working with Excel that will work via windows services.  That is a great product.

Absent all of this, you could run this as a console app and schedule it to run regularly or simply let it run constantly.  I know that works as a solution to this sort of issue with windows services.