Solved

Add COM+ roles using VB Code

Posted on 2004-07-30
1
340 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

816 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now