Automating Enumerating Through Installed MTS Components to Delete a Component
[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 components to delete a component:
- 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
- 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
- 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
- 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
- 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