VB 注册COM+ 删除COM+ 例子源码

sub AddComApp

  strNewName  = “TESTProj”
  RemoveComPlusApplication(strNewName)

  Set oCatalog = CreateObject(“COMAdmin.COMAdminCatalog”)
  Set oApplications = oCatalog.GetCollection(“Applications”)
  oApplications.Populate

  Set oApp = oApplications.Add
  oApp.Value(“Name”) = strNewName
  oApplications.SaveChanges

  strDllPath = “E:\user\DataTrans\test.dll”
  Err.Clear
  Err.Number = 0
  Call oCatalog.InstallComponent(oApp.Name, strDllPath, vbNullString, vbNullString)
  If (Err.Number <> 0) Then
    msgbox Err.Description
  End If

  oApplications.SaveChanges
  Set oApplications = Nothing
  Set oCatalog = Nothing
end sub

Sub RemoveComPlusApplication(strClassName)
  On Error Resume Next
  Dim oCatalog
  Dim oApplications
  Dim oComponents
  Dim miCount
  Dim miCount1
  Dim blnRemovePkg
  Dim numApps
  Dim numComponents
 
  Set oCatalog = CreateObject(“COMAdmin.COMAdminCatalog”)
  Set oApplications = oCatalog.GetCollection(“Applications”)
  oApplications.Populate
   
  ‘ Remove all applications that contain components with strClassName
  numApps = oApplications.Count
  For miCount = numApps – 1 To 0 Step -1
      blnRemovePkg = False
      Set oComponents = oApplications.GetCollection(“Components”, oApplications.Item(miCount).Value(“ID”))
      oComponents.Populate
      numComponents = oComponents.Count
      For miCount1 = numComponents – 1 To 0 Step -1
        If (UCase(oComponents.Item(miCount1).Name) = UCase(strClassName)) Then
           
            ‘There we go, this APP does contains a component with the
            ‘ specified class name.  It needs be removed
           
            blnRemovePkg = True
            Exit For
        End If
      Next
     
      If blnRemovePkg Then
        ‘ Shutdown and Remove
        Call oCatalog.ShutdownApplication(oApplications.Item(miCount).Value(“ID”))
       
        ‘ remove all components in application
        For miCount1 = numComponents – 1 To 0 Step -1
            Call oComponents.Remove(miCount1)
        Next

        Call oApplications.Remove(miCount)
        ‘ Commit our deletions
        oApplications.SaveChanges
      End If
     
      Set oComponents = Nothing
  Next

  Set oApplications = Nothing
  Set oCatalog = Nothing
End Sub

发表评论

您的电子邮箱地址不会被公开。