다음을 통해 공유


IAppHostSectionGroup::Sections 속성

현재 구성 섹션 그룹의 모든 섹션 정의를 포함하는 구성 섹션 정의 컬렉션을 가져옵니다.

구문

HRESULT get_Sections(  
   [out,  
   retval] IAppHostSectionDefinitionCollection** ppSections  
);  

매개 변수

ppSections
IAppHostSectionDefinitionCollection 인터페이스에 대한 포인터에 대한 포인터입니다.

반환 값

HRESULT입니다. 가능한 값에는 다음 표에 있는 값이 포함되지만, 이에 국한되는 것은 아닙니다.

설명
S_OK 작업이 성공했음을 나타냅니다.

예제

다음 코드 예제에서는 새 섹션 그룹과 새 섹션을 만든 다음 새로 생성된 섹션의 속성 값을 설정합니다.


#pragma once

#include <stdio.h>
#include <string.h>
#include <ahadmin.h>

int main()
{
    IAppHostWritableAdminManager * pWMgr       = NULL;
    IAppHostElement              * pParentElem = NULL;
    IAppHostPropertyCollection   * pElemProps  = NULL;
    IAppHostProperty             * pElemProp   = NULL;

    HRESULT hr                   = S_OK;
    BSTR    bstrConfigCommitPath = SysAllocString( L"MACHINE/WEBROOT/APPHOST" );
    BSTR    bstrSectionName      = SysAllocString( L"system.webServer/defaultDocument" );
    BSTR    bstrPropertyName     = SysAllocString( L"enabled" );
    VARIANT vtValue;
    vtValue.vt                   = VT_BOOL;
    vtValue.boolVal              = VARIANT_FALSE;
    VARIANT vtPropertyName;
    vtPropertyName.vt            = VT_BSTR;
    vtPropertyName.bstrVal       = bstrPropertyName;

    // Initialize
    hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
    if ( FAILED( hr ) )
    {
        printf_s( "ERROR: Unable to initialize\n" );
        goto exit;
    } 

    // Create
    hr = CoCreateInstance( __uuidof( AppHostWritableAdminManager ), NULL, 
            CLSCTX_INPROC_SERVER,
            __uuidof( IAppHostWritableAdminManager ), (void**) &pWMgr );
    if( FAILED( hr ) )
    {
        printf_s( "ERROR: Unable to create an IAppHostWritableAdminManager\n" );
        goto exit;
    }
    
    wprintf_s( L"Setting CommitPath: %s\n", bstrConfigCommitPath );
    pWMgr->put_CommitPath( bstrConfigCommitPath );

    if( FAILED( hr ) )
    {
        printf_s( "ERROR: Unable to set the commit path" );
        goto exit;
    }

    // Get the admin section
    wprintf_s( L"Getting section: %s\n", bstrSectionName );

    hr = pWMgr->GetAdminSection( bstrSectionName, bstrConfigCommitPath, &pParentElem );
    if ( FAILED( hr ) || ( &pParentElem == NULL ) )
    {
        if ( E_ACCESSDENIED == hr )
        {            
            printf_s( "ERROR: Access to configuration denied.\n" );
            printf_s( "       Run sample as an administrator.\n" );
        }
        else
        {
            printf_s( "ERROR: Unable to get configuration section.\n" );
        }
        goto exit;
    }

    // Get the property collection
    printf_s( "Getting property collection\n" );

    hr = pParentElem->get_Properties( &pElemProps );
    if ( FAILED ( hr ) || ( &pElemProps == NULL ) )
    {
        wprintf_s( L"ERROR: Unable to access attributes %s\n", bstrSectionName );
        goto exit;
    }

    // Get the property instance
    wprintf_s ( L"Getting property: %s\n", bstrPropertyName );

    hr = pElemProps->get_Item( vtPropertyName, &pElemProp );
    if ( FAILED( hr ) || ( pElemProp == NULL ) )
    {
        wprintf_s( L"ERROR: Unable to access attribute: %s\n", bstrPropertyName );
        goto exit;
    }

    // Set the property value
    wprintf_s( L"Setting property: %s to %s\n", bstrPropertyName, 
        ( vtValue.boolVal == VARIANT_TRUE ? L"true" : L"false" ) );

    hr = pElemProp->put_Value( vtValue );
    if ( FAILED( hr ) )
    {    
        wprintf_s( L"ERROR: Unable to set attribute value: %s\n", bstrPropertyName );
        goto exit;
    }

    // Commit the changes to the configuration system

    hr = pWMgr->CommitChanges();
    if( FAILED( hr ) )
    {
        printf_s( "ERROR: Unable to commit the changes to the configuration system" );
    }

exit:
    // Exiting / Unwinding
    if ( pElemProp != NULL )
    {
        pElemProp->Release();
        pElemProp = NULL;
    }
    if ( pElemProps != NULL )
    {
        pElemProps->Release(); 
        pElemProps = NULL;
    }
    if ( pParentElem != NULL )
    {
        pParentElem->Release(); 
        pParentElem = NULL;
    }
    if ( pWMgr != NULL )
    {
        pWMgr->Release(); 
        pWMgr = NULL;
    }

    SysFreeString( bstrPropertyName );
    SysFreeString( bstrConfigCommitPath );
    SysFreeString( bstrSectionName );

    // Uninitialize
    CoUninitialize();

    return 0;
};

요구 사항

형식 Description
클라이언트 - Windows Vista의 IIS 7.0
- Windows 7의 IIS 7.5
- Windows 8의 IIS 8.0
- WINDOWS 10 IIS 10.0
서버 - Windows Server 2008의 IIS 7.0
- Windows Server 2008 R2의 IIS 7.5
- Windows Server 2012의 IIS 8.0
- Windows Server 2012 R2의 IIS 8.5
- WINDOWS SERVER 2016 IIS 10.0
제품 - IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0
- IIS Express 7.5, IIS Express 8.0, IIS Express 10.0
헤더 Ahadmin.h

참고 항목

IAppHostSectionGroup 인터페이스