如何在程序中判断需要运行的控件是否已经存在(已经注册),并根据结果进行是否安装和注册该控件?

解决方案 »

  1.   

    ...
        On Error Resume Next    Dim oComponentCheck As stdole.IUnknown    ' Check whether the specified component is installed and registered.
        Set oComponentCheck = CreateObject("COMName.ClassName")
        m_fComponentInstalled = (Err.Number = 0)
        ...
      

  2.   

    要在程序里注册的话,随便调个Shell,执行regsvr32 <component file name>就得了~
      

  3.   

    to realkk:
    谢谢,我试过,好像对组件是可以的,不过ActiveX控件(.ocx)好像就不行。
    在VB中,CreateObject的声明是这样的:
    Public Shared Function CreateObject( _
       ByVal ProgId As String, _
       Optional ByVal ServerName As String = "" _
    ) As Object
    控件的ProgID是什么?
      

  4.   

    其实是一样的,控件其实也是类, 下面是我自己做过的代码:Dim oCheckup As stdole.IUnknown' Check whether the activeX control ControlName is installed and registered.
    Set oCheckup = CreateObject("OCXLib.ControlName")
    m_fPerfectView = (Err.Number = 0)其中OCXLib.ControlName中的OCXLib是ActiveX ocx的工程名,也就是库名(不一定是ocx的文件名);ControlName是这个库里面的一个控件名.