Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error "Cannot create Active X component" from Windows service but not console Application

Tags:

c#

com

activex

I have a Windows service written in c# which keeps listening to one Event Hub in Azure. As soon as a message is received, the service processes the message and does some execution and calculation.

As part of the execution, it launches a application called AutoCal (company's own window's application), which is COM component similar to that of Excel.

Earlier I had a web api which does the same calculation/execution. Upon every request it opens AutoCal and does some processing. I have added the AutoCal DLL as reference in the project.

The code to open AutoCal is something similar:

(AutoCal.Application)Interaction.CreateObject("AutoCal.Application.NewInstance").

When I tested this locally, it has perfectly as expected. But once I hosted this on the server, it has thrown an error saying "Cannot create ActiveX component". To rectify this, I have given permission to open COM components to Application Pool of IIS. This has resolved my issue.

Now that I have a windows service which also open the AutoCal, from where do I give CO component permissions. I have searched for it, but everywhere the solution is for ASP.net only.

How can I rectify this issue for Windows service?

PS: When I have written same code in console application, it is working fine.

like image 675
CrazyCoder Avatar asked Mar 23 '26 06:03

CrazyCoder


1 Answers

Without having exact error logs (can you try looking for related errors in the EventViewer?) it's hard to tell what the problem is.

But I would try the following:

  1. In the start menu type Component services and open it (right click - as admin!)
  2. Go to Component services -> My Computer -> DCOM Config folder

You'll see something like this

DCOM Config

  1. Find your COM Application in the tree.
  2. Right click it, open properties, go to Security Tab

It will look like this (never mind the title of the tab in the picture, in your case it should be something like AutoCal):

COM object properties

If it's grayed out, like in my case, you can use the following procedure to change the settings on your system, and make this tab configurable:

  1. Go to Start > Run. Enter regedit
  2. Go to the key that is associated with the DCOM component you want to manage: HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID\{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
  3. Right click on it. Select Permissions
  4. Click Advanced
  5. Change the owner to Administrator or your user account
  6. Click OK
  7. Select Full Control for the Administrators group and owner you selected
  8. Go to Start > Run. Search for services. Find COM+ System Application. Right click on the service, then click Restart

Registry tempering

Once you have the Security tab enabled, you can change the permissions for your COM object. For example - you can allow the user, under which your service runs, to access or activate this COM object.

I hope this helps you, but again, without any additional error info - it's a long shot.

like image 163
Aryéh Radlé Avatar answered Mar 25 '26 20:03

Aryéh Radlé



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!