How do I get the path of a registered COM server in C#?

301 views Asked by At

Is there a nice way to programmatically get the path of a registered COM server in C#?

We have an out-of-process COM server (i.e., an exe-file) that we reference in our C# project; however we want to enforce that we run the COM server from a specific location, so we'd like to check the path of the registered exe-file before starting it. Is there a good way to do this, besides diving into the registry?

1

There are 1 answers

0
Anders Gaarde On

The function QueryPathOfRegTypeLib does just that.

However, I did notice a strange quirk:

If I first register from one path on a per-user basis:

c:\Path1\comserver.exe /regserverperuser

and then register from another path on a system level basis:

c:\Path2\comserver.exe /regserver

Then QueryPathOfRegTypeLib returns c:\Path1\comserver.exe, but it is actually c:\Path2\comserver.exe which is started when you load the type library...