简体   繁体   English

如何获取C#中注册的COM服务器的路径?

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

Is there a nice way to programmatically get the path of a registered COM server in C#? 有没有一种好的方法以编程方式获取C#中已注册的COM服务器的路径?

We have an out-of-process COM server (ie, an exe-file) that we reference in our C# project; 我们有一个C#项目中引用的进程外COM服务器(即exe文件)。 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. 但是,我们要强制我们从特定位置运行COM服务器,因此我们想在启动之前检查已注册exe文件的路径。 Is there a good way to do this, besides diving into the registry? 除了深入注册表之外,还有什么好方法吗?

The function QueryPathOfRegTypeLib does just that. 函数QueryPathOfRegTypeLib就是这样做的。

However, I did notice a strange quirk: 但是,我确实注意到了一个奇怪的怪癖:

If I first register from one path on a per-user basis: 如果我首先基于每个用户从一个路径进行注册:

c:\\Path1\\comserver.exe /regserverperuser c:\\ Path1 \\ comserver.exe / regserverperuser

and then register from another path on a system level basis: 然后在系统级别上从其他路径进行注册:

c:\\Path2\\comserver.exe /regserver 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... 然后QueryPathOfRegTypeLib返回c:\\ Path1 \\ comserver.exe,但实际上是c:\\ Path2 \\ comserver.exe,它是在加载类型库时启动的...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM