Automating Creating a New MTS Package and Installing Components

To create a new package named ôMy Packageö and install the components in that package:

  1. Declare the objects that you will be using to create a new package and install components into that package.
    	Dim catalog As Object
        Dim packages As Object
        Dim newPack As Object
        Dim componentsInNewPack 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 top level Packages collection from the CatalogCollection object by calling the GetCollection method. Then call the Add method to add a new package.
    	Set catalog = CreateObject("MTSAdmin.Catalog.1")
    Set packages = catalog.GetCollection("Packages") Set newPack = packages.Add Dim newPackID As String
  4. Set the package name to ôMy Packageö and save changes to the Packages collection.
        newPackID = newPack.Key
       	 newPack.Value("Name") = "My Package"
       	 packages.SaveChanges
  5. Call the GetCollection method to access the ComponentsInPackage collection. Then instantiate the ComponentUtil object in order to call the InstallComponent method to populate the new package with components.
    	Set componentsInNewPack = 	packages.GetCollection("ComponentsInPackage", newPackID)
      	  Set util = componentsInNewPack.GetUtilInterface
       	 util.InstallComponent"d:\dllfilepath", "", ""
       	 Exit Sub
  6. 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


© 1997 Microsoft Corporation. All rights reserved.