检测是否安装了COM组件的最佳方法是什么 [英] What is the best way to detect if a COM component is installed

查看:161
本文介绍了检测是否安装了COM组件的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个COM互操作程序集,我想从一个.NET应用程序检查我即将创建的组件是否已安装在机器上。

I have a COM interop assembly, and I would like to check from a .NET application whether the component I'm about to create is installed on the machine.

如果没有安装,我想提供一个不错的错误讯息。

I would like to provide a nice error message if it is not installed.

-catch对我来说不是一个好的解决方案,因为我想在缺少的安装和可能发生的其他错误之间distingwish。

Put the instantiation into try-catch is not a good solution for me, as I would like to distingwish between the missing installation and the other errors that may occur.

我的想法是检查具有COM类别id的节点是否存在于注册表中的 HKEY_LOCAL_MACHINE \SOFTWARE \Classes\Interface 路径。但是有更好的方法吗?

My idea is to check whether the node with the COM class id exists in the registry under the HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Interface path. But is there a better approach?

推荐答案

我认为最好的方法,不幸的是,尝试并实例化它。检查注册表并不保证组件实际上存在(例如,该文件可能已在注册后被删除或移动)。

I think the best way, unfortunately, is to try and instantiate it. Checking in the registry does not guarantee that the component is actually there at all (e.g. the file may have been deleted or moved post registration).

这篇关于检测是否安装了COM组件的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆