Error with Excel and C# when logged off the server

3

I have written a Windows Service in C#. My service is meant to open an Excel macro-enabled workbook (this is in Excel 2010). I have installed this service on our server which is running Windows Server 2008 64-bit. My service seems to have a problem launching Excel when no one is logged on the server, does anyone have a solution to this?

I get the following error:

System.Runtime.InteropServices.COMException (0x8000401A): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 8000401a.

Excel is installed on the server, the service works fine when I am logged on the server but once all users have logged off, I get the above error. I would like the service to launch my Excel workbook regardless of an open session on the server or not.

c#
.net
excel
windows-services
asked on Stack Overflow Jan 31, 2012 by Rowena Reddy • edited Nov 3, 2016 by Vikrant

3 Answers

5

My service seems to have a problem launching Excel when no one is logged on the server, does anyone have a solution to this.

Of course it has a problem. Windows Services cannot show a user interface, so how would you expect it to launch a GUI application like Microsoft Excel when there is no user logged in?

The specific COM error code that you receive means:

8000401a: The server process could not be started because the configured identity is incorrect. Check the username and password.

In other words, Excel is trying to start as an interactive user, which refers to the user that is currently logged on directly to the server console. Since no user is logged on, no interactive user exists, and the application fails when it tries to assume this identity.

The design was broken anyway: Excel was not designed to be run from a Windows Service. Create a standard Windows application instead. If you need it to run in the background without a UI of its own, don't create a window.

answered on Stack Overflow Jan 31, 2012 by Cody Gray • edited May 23, 2017 by Community
1

Basically, Cody Gray's answer is right. In the past I had a need to launch Excel from a Windows Service in order to print the file.

We were able to get past that kind of errors by setting the service to run as a specific user account and from time to time, log on as that user account and try to launch the files that failed to see the error messages popped up by Excel.

In your case, it is possibly because Excel is started for the first time and it asks you for something like your initials.

answered on Stack Overflow Jan 31, 2012 by Marcel Gosselin
1

Are you using Office Automation to start Excel? Sorry, but Office Automation is not supported in service processes. It is designed to work only in an interactive process.

If you're lucky, Using Office Automation from a service process won't work. If you're not lucky, it will appear to work, and you'll actually put your application into production. You'll then start finding random bugs which are very difficult to reproduce, and even more difficult to fix without breaking something else.

That will be due to the fact that the real bug is a design bug - you used Office Automation from a service process.

Take it from the Voice of Experience...

answered on Stack Overflow Jan 31, 2012 by John Saunders

User contributions licensed under CC BY-SA 3.0