Dim catalog As Object
Dim packages As Object
Dim pack As Object
Dim comp As Object
Dim newUser As Object
Dim newRole As Object
Dim componentsInPack As Object
Dim RolesInPackage As Object
Dim usersInRole As Object
Dim rolesForComponent As Object
Dim util As Object
On Error GoTo failed
Set catalog = CreateObject("MTSAdmin.Catalog.1")
Set packages = catalog.GetCollection("Packages")
packages.Populate
If pack.Name = "My Package" Then
Set rolesInPack = packages.GetCollection("RolesInPackage", pack.Key)
Set newRole = rolesInPack.Add
newRole.Value("Name") = "R1"
rolesInPack.savechanges
Set usersInRole = RolesInPackage.GetCollection("UsersInRole", newRole.Key)
Set newUser = usersInRole.Add
newUser.Value("User") = "administrator"
usersInRole.savechanges
Set componentsInPack = packages.GetCollection("ComponentsInPackage", pack.Key)
componentsInPack.Populate
For Each comp In componentsInPack
If comp.Name = "Bank.Account" Then
Set rolesForComponent = componentsInPack.GetCollection("RolesForPackageComponent", comp.Key)
Set util = rolesForComponent.GetUtilInterface
util.associateRole (newRole.Key)
Exit For
End If
Next
Exit For
End If
Next
Exit Sub
failed:
MsgBox "Failure code " + Str$(Err.Number)
End Sub
See Also
MTS Administration Objects, MTS Collection Types, MTS Administration Object Methods, Automating MTS Administration with Visual Basic