다음을 통해 공유


COM+ 관리 카탈로그를 사용하는 소개 예제

COM+ 관리 카탈로그를 프로그래밍 방식으로 사용하는 경우 일반적으로 다음과 같은 일반적인 단계를 수행합니다(여기서는 엄격한 순서로 지정되지 않음).

  • 로컬 컴퓨터에서 COM+ 카탈로그를 사용하여 세션을 엽니다. 필요에 따라 원격 컴퓨터의 COM+ 카탈로그에 연결합니다.
  • 서비스 시작 또는 중지와 같은 작업( 특정 COM+ 애플리케이션과 관련이 없는 작업)을 수행합니다.
  • COM+ 애플리케이션 설치 또는 내보내기 또는 구성 요소를 애플리케이션에 설치하는 등의 작업(파일에서 읽거나 파일에 쓰는 작업)을 수행합니다.
  • "애플리케이션" 컬렉션에 새 항목을 추가하여 새 COM+ 애플리케이션을 만드는 등 컬렉션에 새 항목을 추가합니다.
  • 컬렉션의 항목에 대한 속성을 설정하거나 가져옵니다.
  • 카탈로그에 보류 중인 변경 내용을 저장하거나 취소합니다.
  • 발생할 수 있는 모든 오류를 처리합니다.

COMAdmin 개체를 사용할 때 이러한 단계의 모양을 표시하기 위해 아래에 Microsoft Visual Basic 예제가 제공됩니다. 위에서 설명한 일반적인 단계 중 일부(예: 컬렉션 찾기, 항목을 검색하기 위해 컬렉션 열거, 해당 항목의 속성 설정)를 간략하게 보여 줍니다.

아래 예제에서는 다음 작업을 수행합니다.

  1. 새 COM+ 애플리케이션 "MyHomeZoo"를 만듭니다.
  2. 일부 구성 요소인 Cat 및 Dog를 애플리케이션에 설치합니다. 두 구성 요소는 모두 이미 존재해야 하는 단일 DLL(MyZoo.dll)에 포함되어 있습니다.
  3. ZooKeeper 및 AllergicToCats의 두 가지 역할을 정의하여 애플리케이션에 대한 역할 기반 보안을 구성합니다.
  4. 전체 애플리케이션에 ZooKeeper 역할 액세스 권한을 할당합니다.
  5. Dog 구성 요소에만 AllergicToCats 역할 액세스 권한을 할당합니다.
  6. 애플리케이션에 대해 역할 검사가 적용되도록 보안 속성을 켭니다.
  7. MyHomeZoo 애플리케이션을 다른 컴퓨터에 설치할 수 있도록 파일로 내보냅니다.

Visual Basic에서 이 예제를 사용하려면 COM+ 관리 형식 라이브러리에 대한 참조를 추가합니다.

Function SetupMyZoo() As Boolean  ' Return False if any errors occur.

    '  Initialize error handling for this function.
    SetupMyZoo = False 
    On Error GoTo My_Error_Handler

    '  Open a session with the catalog.
    '  Instantiate a COMAdminCatalog object. 
    Dim objCatalog As COMAdminCatalog
    Set objCatalog = CreateObject("COMAdmin.COMAdminCatalog")

    '  Create a new COM+ application.
    '  First get the "Applications" collection from the catalog.
    Dim objApplicationsColl As COMAdminCatalogCollection
    Set objApplicationsColl = objCatalog.GetCollection("Applications")

    '  Add a new item to this collection. 
    Dim objZooApp As COMAdminCatalogObject
    Set objZooApp = objApplicationsColl.Add

    '  The "Applications" collection determines the available properties.
    '  Set the "Name" property of the new application item. 
    objZooApp.Value("Name") = "MyHomeZoo"

    '  Set the "Description" property of the new application item. 
    objZooApp.Value("Description") = "My pets at home"

    '  Save changes made to the "Applications" collection. 
    objApplicationsColl.SaveChanges

    '  Install components into the application.
    '  Use the InstallComponent method on COMAdminCatalog. 
    '  In this case, the last two parameters are passed as empty strings.
    objCatalog.InstallComponent "MyHomeZoo","MyZoo.DLL","","" 

    '  Define the roles ZooKeeper and AllergicToCats 
    '  by adding them to the "Roles" collection related to MyHomeZoo. 
    '  First get the "Roles" collection related to MyHomeZoo.
    '  Use the GetCollection method on COMAdminCatalogCollection,
    '  passing in the name of the desired collection, "Roles", 
    '  and the Key property value of objZooApp.   
    '  The Key property uniquely identifies the object, serving
    '  here to distinguish the "Roles" collection related 
    '  to MyHomeZoo from that of any other application. 
    Dim objRolesColl As COMAdminCatalogCollection
    Set objRolesColl = objApplicationsColl.GetCollection("Roles", objZooApp.Key)

    '  Add new items to this "Roles" collection. 
    Dim objZooKeeperRole As COMAdminCatalogObject
    Dim objAllergicToCatsRole As COMAdminCatalogObject
    Set objZooKeeperRole = objRolesColl.Add
    Set objAllergicToCatsRole = objRolesColl.Add

    '  Set the "Name" for the new items.
    objZooKeeperRole.Value("Name") = "ZooKeeper" 
    objAllergicToCatsRole.Value("Name") = "AllergicToCats" 

    '  Save changes made to any items in this "Roles" collection. 
    objRolesColl.SaveChanges

    '  Assign the AllergicToCats role to the Dog component to 
    '  restrict its scope of access. (The ZooKeeper role, if assigned
    '  only at the application level, can access the whole application.)
    '  First get the "Components" collection related to MyHomeZoo.
    '  Use the GetCollection method on COMAdminCatalogCollection,
    '  passing in the name of the desired collection, "Components", and
    '  the Key property value of objZooApp. 
    Dim objZooComponentsColl As COMAdminCatalogCollection
    Set objZooComponentsColl = objApplicationsColl.GetCollection("Components", objZooApp.Key) 

    '  Find the Dog component item in this "Components" collection.
    '  First Populate the collection to read in data for all its items. 
    objZooComponentsColl.Populate

    '  Enumerate through the "Components" collection 
    '  until the Dog component item is located. 
    Dim objDog As COMAdminCatalogObject 
    For Each objDog in objZooComponentsColl
        If objDog.Name = "Dog" Then 
            Exit For
        End If
    Next 
    '  Set the role checking property at the component level for Dog.
        objDog.Value("ComponentAccessChecksEnabled") = True 

    '  Save these changes.
        objZooComponentsColl.SaveChanges
    '  Get the "RolesForComponent" collection related to the 
    '  Dog component, using the Key property of objDog. 
    Dim objRolesForDogColl As COMAdminCatalogCollection 
    Set objRolesForDogColl = objZooComponentsColl.GetCollection("RolesForComponent", objDog.Key) 

    '  Add a new item to this "RolesForComponent" collection. 
    Dim objCatSneezerRole As COMAdminCatalogObject
    Set objCatSneezerRole = objRolesForDogColl.Add

    '  Set the "Name" of the new item to be "AllergicToCats". 
    objCatSneezerRole.Value("Name") = "AllergicToCats" 

    '  Save changes made to this "RolesForComponent" collection. 
    objRolesForDogColl.SaveChanges

    '  Now set properties to enforce role-based security. 
    '  First set role-based security at the application level.
    objZooApp.Value("ApplicationAccessChecksEnabled") = True 
    objZooApp.Value("AccessChecksLevel") = COMAdminAccessChecksApplicationComponentLevel 

    '  Save these changes.
    objApplicationsColl.SaveChanges

    '  Finally, export the new configured MyHomeZoo application to an 
    '  MSI file, used to install the application on other machines.
    '  Use the ExportApplication method on COMAdminCatalogObject.
    objCatalog.ExportApplication "MyHomeZoo", "c:\Program Files\COM applications\MyHomeZoo.MSI", 4

    '  Exit the function gracefully.
    SetupMyZoo = True

My_Error_Handler:
    If Not SetupMyZoo Then
        MsgBox "Error # " & Err.Number & " (Hex: " & Hex(Err.Number) & ")" & vbNewLine & Err.Description
    End If
    objCatSneezerRole = Nothing
    objRolesForDogColl = Nothing
    objDog = Nothing
    objZooComponentsColl = Nothing
    objAllergicToCatsRole = Nothing
    objZooKeeperRole = Nothing
    objRolesColl = Nothing
    objZooApp = Nothing
    objApplicationsColl = Nothing
    objCatalog = Nothing
Exit Function

트랜잭션 내의 COM+ 관리 작업

COM+ 관리 오류 처리

COMAdmin 개체 개요

COM+ 카탈로그에서 컬렉션 검색

COM+ 카탈로그에 속성 설정 및 변경 내용 저장