Automating Enumerating Through Installed MTS Components to Delete a Component

To enumerate through installed components to delete a component:
  1. Declare the objects that you will be using to enumerate through installed components to delete a specific component.
    Dim catalog As Object
    Dim packages As Object
    Dim pack As Object
    Dim componentsInPack As Object
    Dim util As Object
  2. Use the On Error statement to handle run-time errors if a method returns a failure HRESULT. You can test and respond to MTS trappable errors using the On Error statement and the Err object.
    On Error GoTo failed
  3. Call the CreateObject method to instantiate the Catalog object. Retrieve the Packages collection by calling the GetCollection method. Then call the Populate method to fill the collection with packages installed in the catalog.
    Set catalog = CreateObject("MTSAdmin.Catalog.1")
    Set packages = catalog.GetCollection("Packages")
    packages.Populate
  4. Enumerate through the collection to look for the package named “My Package.” Then call the GetCollection method to get the ComponentsInPackage collection. Fill the ComponentInPackages collection using the Populate method, and then enumerate through the collection to find the “Bank.Account” component. Call the Remove method to delete the component, and save changes to the collection by calling the SaveChanges method.
    For Each pack In packages
            If pack.Name = "My Package" Then
                Set componentsInPack = packages.GetCollection("ComponentsInPackage", pack.Key)
                componentsInPack.Populate
                For i = 0 To componentsInPack.Count
                    Set comp = componentsInPack.Item(i)
                    If comp.Name = "Bank.Account" Then
                        componentsInPack.Remove (i)
                        componentsInPack.savechanges
                        Exit For
                    End If
    Next
                Exit For
            End If
        Next
               
        Exit Sub
  5. Use the Err object to display an error message if the installation of the package fails.
    failed:
        MsgBox "Failure code " + Str$(Err.Number)
    
    End Sub

See Also

MTS Administration Objects, MTS Collection Types, MTS Administration Object Methods, Automating Advanced MTS Administration with Visual Basic