共用方式為


IAppHostAdminManager::GetMetadata 方法

從 IIS 7 組態系統取得中繼資料值。

語法

HRESULT GetMetadata(  
   [in,  
   string] BSTR bstrMetadataType,  
   [out,  
   retval] VARIANT* pValue  
);  

參數

bstrMetadataType
BSTR,其中包含所要求之中繼資料的名稱。

pValue
的指標 VARIANT ,其中包含所要求中繼資料的值。

傳回值

HRESULT。 可能的值包括 (但不限於) 下表中的這些值。

描述
S_OK 表示作業成功。
ERROR_NOT_SUPPORTED 表示不支援要求的中繼資料。

範例

下列程式碼範例會 availableSections 使用 IAppHostAdminManager::GetMetadata 方法,從組態架構擷取中繼資料。


#pragma once

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

int main()
{
    IAppHostAdminManager *    pMgr  = NULL;
    HRESULT hr                      = S_OK;
    BSTR    bstrMetadataName        = SysAllocString( L"availableSections" );
    VARIANT vtAvailableSections;
    
    // Initialize
    hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
    if ( FAILED( hr ) )
    {
        printf_s( "ERROR: Unable to initialize\n" );
        goto exit;
    } 

    // Create
    hr = CoCreateInstance( __uuidof( AppHostAdminManager ), NULL, 
            CLSCTX_INPROC_SERVER,
            __uuidof( IAppHostAdminManager ), (void**) &pMgr );
    if( FAILED( hr ) )
    {
        printf_s( "ERROR: Unable to create an IAppHostAdminManager instance\n" );
        goto exit;
    }

    // Get the metadata
    hr = pMgr->GetMetadata( bstrMetadataName, &vtAvailableSections );
    if ( FAILED( hr ) )
    {
        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 the requested metadata.\n" );
        }
        goto exit;
    }

    // Metadata returns in a comma-delimited string.
    // Split the data and return the sections one line at a time.
    wchar_t* wcMetadata = static_cast<wchar_t*>(vtAvailableSections.bstrVal);
    wchar_t  delim[]   = L",";
    wchar_t* tokenIn = NULL;
    wchar_t* tokenOut = NULL;

    tokenIn = wcstok_s( wcMetadata, delim, &tokenOut );
    while ( tokenIn != NULL ) 
    {
        wprintf_s( L"\t%s\n", tokenIn );
        tokenIn = wcstok_s( NULL, delim, &tokenOut);
    }
exit:
    // Exiting / Unwinding
    if ( pMgr != NULL )
    {
        pMgr->Release(); 
        pMgr = NULL;
    }

    SysFreeString( bstrMetadataName );

    // Uninitialize
    CoUninitialize();
    return 0;
};

規格需求

類型 描述
Client - 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

另請參閱

IAppHostAdminManager 介面