Solved

Add COM+ roles using VB Code

Posted on 2004-07-30
1
342 Views
Last Modified: 2010-05-02
Hi Experts,

I wanted to know how to add existing roles to a component that i add. I have got 3 roles and i want to add these to the components.
I have done most of the code to add a role but could not get the role checked in the security tab od the COM+.

In simple, How do i add a role to a component using vb code.
any sample would be of great help.

working sample contains 100 pts extra.

Thanks in Advance for all the Experts,
Bhalpa
0
Comment
Question by:bhalpa
1 Comment
 
LVL 26

Accepted Solution

by:
EDDYKT earned 250 total points
ID: 11678130
Try this

Dim catalog As New COMAdminCatalog
    Dim packages As COMAdminCatalogCollection
    Dim package As COMAdminCatalogObject
    Dim components As COMAdminCatalogCollection
    Dim component As COMAdminCatalogObject
    Dim roles As COMAdminCatalogCollection
    Dim role As COMAdminCatalogObject
    Dim users As COMAdminCatalogCollection
    Dim user As COMAdminCatalogObject
    Dim roleUtil As COMAdminCatalogCollection 'RoleAssociationUtil
    Dim computer As COMAdminCatalogCollection
   
    On Error Resume Next
    Set packages = catalog.GetCollection("Applications")
    packages.Populate
   
    ' Locate desired package
    For Each package In packages
        If package.Value("Name") = "YourPackageName" Then
            Exit For
        End If
    Next
   
    If package Is Nothing Then Exit Sub
   
    ' Iterate through the components and add 'Everyone' to each role
    Set components = packages.GetCollection("Components", package.Key)
    components.Populate
    For Each component In components
        Set roles = components.GetCollection("RolesForComponent", component.Key)
        roles.Populate
        If roles.Count = 0 Then
            Set role = roles.Add
            role.Value("Name") = "Everyone"   ' replace your role name here
            roles.SaveChanges
        End If
    Next
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question