The Visual Basic version 5.0 sample application demonstrates how to use the methods on the Catalog, CatalogObject, and CatalogCollections objects to automate basic administration functionality for a package named “Scriptable Admin Demo.”
Note You must configure your Visual Basic project to reference the MTS administrative type library (MTSAdmin type library). To reference the MTSAdmin type library, select the References option from the Visual Basic Project toolbar. Then browse the available reference files for the “MTS 2.0 Admin Type Library.” For late-binding variables (binding that occurs when you run the program), Visual Basic will locate the type library without further configuration if the MTXADMIN.DLL file is registered on your local machine.
To delete any existing packages named “Scriptable Admin Demo”Dim catalog As Object
Set catalog = CreateObject("MTSAdmin.Catalog.1")
Dim packages As Object
Set packages = catalog.GetCollection("Packages")
packages.Populate
Dim pack As Object
n = packages.Count
For i = n - 1 To 0 Step -1
If packages.Item(i).Value("Name") = "Scriptable Admin Demo" Then
packages.Remove (i)
End If
Next
packages.SaveChanges
To create a new package named “Scriptable Admin Demo Package”Dim newPack As Object
Dim newPackID As Variant
Set newPack = packages.Add
newPackID = newPack.Value("ID")
newPack.Value("Name") = "Scriptable Admin Demo"
newPack.Value("SecurityEnabled") = "N"
n = packages.SaveChanges
To update the “Scriptable Admin Demo” package properties and get the ComponentsInPackage collection.Dim keys(0) as Variant
keys(0) = newPackId
packages.PopulateByKey keys
Dim package As Object
Set package = packages.Item(0)
package.Value("SecurityEnabled") = "Y"
Set components = packages.GetCollection("ComponentsInPackage",_ package.Key)
packages.SaveChanges
To install a componentasdefcomponent into the "Scriptable Admin Demo package":Dim util As Object
Set util = components.GetUtilInterface
On Error GoTo installFailed
Form2.Show 1
Dim thePath As String
thePath = Form2.MTSPath + "\samples\packages\vbacct.dll"
util.InstallComponent thePath, "", ""
Dim installedCLSIDs() as Variant
util.GetCLSIDs thePath, “”, installedCLSIDs
On Error GoTo 0
components.PopulateByKey installedCLSIDs
To find and delete the Bank.CreateTable component from the "Scriptable Admin Demo package":Dim component As Object
n = components.Count
For i = n - 1 To 0 Step -1
Set component = components.Item(i)
component.Value("Transaction") = "Required"
Bank.CreateTable component by index. Note that you must iterate though the collection backwards in order to call the Remove method during the loop. If component.Value("ProgID") = "Bank.CreateTable" Then
components.Remove (i)
End If
Next
Bank.CreateTable component will not be deleted from the data store until the SaveChanges method is called. Display a message box that informs the user if the installation succeeded.n = components.Count
For i = 0 To n - 1
Set component = components.Item(i)
Debug.Print component.Value("ProgID")
Debug.Print component.Value("DLL")
Next
n = components.SaveChanges
MsgBox "Scriptable Admin Demo package installed and configured."
Exit Sub
installFailed:
MsgBox "Error code " + Str$(Err.Number) + " installing " + thePath + " Make sure the MTS path you entered is correct and that vbacct.dll is not already installed."
End Sub
See Also
MTS Administration Objects, MTS Collection Types, MTS Administration Object Methods, Automating MTS Administration with Visual Basic, Automating Advanced MTS Administration with Visual Basic