Platform SDK: Transaction Server

Automating Enumerating Through Installed MTS Packages to Delete a Package

[This product will work only on Windows NT 4.0 versions and earlier. For Windows 2000 and later, see COM+ (Component Services).]

To enumerate through installed packages to delete the package named “My Package”:

  1. Declare the objects that you will be using to enumerate through installed packages to delete a specific package.
    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. Use the Count and Item methods to enumerate through the package collection to find the package named “My Package.” When “My Package” is located, call the Remove method to delete the package. Then save changes to the collection by calling the SaveChanges method.
    For i = 0 To packages.Count-1
            Set pack = packages.Item(i)
            If pack.Name = "My Package" Then
                packages.Remove (i)
                packages.savechanges
                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