Automating COM+ Applications Management Using VBScript

I wanted a script to add the Network Service account to all available roles for a specific COM+ application, however, it seems to be really hard to find out how to script these actions. Anyway after some research here is a sample script to assign the Network Service account in this case to all roles within the Sample COM+ application.

'' Setup variables
Const ApplicationName = "Sample"
Const AccountName = "NT AUTHORITY\NETWORK SERVICE"

'' Setup COM+ Application Catalog Object
Set Catalog = CreateObject("COMAdmin.COMAdminCatalog")
Set apps = Catalog.GetCollection("Applications")
''Populate the object with Applications from the COM Admin Catalog object
apps.populate

'' Loop for each application in the array
For each app in apps
'' Check for my application
    If app.Name = ApplicationName then
    '' If the application is found perform actions then create the roles object
        '' Clear the application Authentication Access Checks value
        app.Value("ApplicationAccessChecksEnabled") = false
        '' Set the application identity to be the Network Service
        app.Value("Identity") = "NT AUTHORITY\NetworkService"
        '' Save the changes to the application object
        apps.SaveChanges
        Set roles = apps.GetCollection("Roles", app.key)
        '' Populate the roles array with the roles from the current application in the initial loop
        roles.populate
        '' Loop each role in the roles array
        For each role in roles
            '' Setup the users array by getting the UsersInRole attribute
            Set users = roles.GetCollection("UsersInRole", role.Key)
            '' Add a new element in the array for the new user
            Set user = users.Add
            '' Set the user to add as the AccountName variable
            user.Value("User") = AccountName
            '' Save the changes to the array back to the COM+ Application
            users.SaveChanges
        '' Progress the roles loop
        Next
    '' Escape the If statment
    End If
'' Progress the application loop
Next

There is a useful MDSN article outlining all the avaliable object properties here

Hopefully this helps you automate your own COM+ Application administration.

One Reply to “Automating COM+ Applications Management Using VBScript”

  1. This saves me a ton of work… THX!!! I had an x64 COM+ which was flooding the Eventlog with Security Warnings. Now i adapted your script to add DOMAIN USERS and my Security Warnings are gone. Will deploy that via Package on my XA65 Farm. Best regards from Germany Oliver

Leave a Reply