IAppHostWritableAdminManager::CommitPath 属性

获取或设置应在其中提交更改的配置路径。

语法

HRESULT get_CommitPath(  
   [out,  
   retval,  
   string] BSTR* pbstrCommitPath  
);  
HRESULT put_CommitPath(  
   BSTR bstrCommitPath  
);  

parameters

pbstrCommitPath
指向 的 BSTR 指针,其中包含应在其中提交更改的配置路径。

bstrCommitPath
一个 BSTR 包含新提交路径的 。

返回值

HRESULT。 可能的值包括(但并不限于)下表中的项。

说明
S_OK 指示操作成功。

示例

下面的代码示例演示如何设置 CommitPath 属性、更改 IIS 7 配置,然后使用 IAppHostWritableAdminManager::CommitChanges 方法将这些更改提交到 IIS 7 配置系统。


#pragma once

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

int main()
{
    IAppHostWritableAdminManager *    pWMgr       = NULL;
    IAppHostElement              *    pElement    = NULL;
    
    HRESULT  hr                   = S_OK;
    BSTR     bstrConfigCommitPath = SysAllocString(L"MACHINE/WEBROOT/APPHOST");
    BSTR     bstrSectionName      = SysAllocString(L"system.applicationHost/sites");
    BSTR     bstrConfigSource     = SysAllocString(L"sites.config");
    BSTR     bstrConfigSourceAttr = SysAllocString(L"configSource");
    VARIANT  vtConfigSource;
    vtConfigSource.vt             = VT_BSTR;
    vtConfigSource.bstrVal        = bstrConfigSource;

    // 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 instance\n" );
        goto exit;
    }

    // Set the commit path
    hr = pWMgr->put_CommitPath( bstrConfigCommitPath );
    if ( FAILED( hr ) )
    {
        printf_s( "ERROR: Unable to set the configuration path" );
        goto exit;
    }

    // Get the admin section
    hr = pWMgr->GetAdminSection( bstrSectionName, bstrConfigCommitPath, &pElement );
    if ( FAILED( hr ) || ( &pElement == 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 asp configuration section.\n" );
        }
        goto exit;
    }
        
    // Set the metadata
    hr = pElement->SetMetadata( bstrConfigSourceAttr, vtConfigSource );
    if ( FAILED( hr ) )
    {
        printf_s( "ERROR: Unable to set metadata\n" );
        goto exit;
    }

    pWMgr->CommitChanges();
exit:
    // Exiting / Unwinding
    if ( pElement != NULL )
    {
        pElement -> Release ();
        pElement = NULL;
    }

    if ( pWMgr != NULL )
    {
        pWMgr->Release(); 
        pWMgr = NULL;
    }

    SysFreeString( bstrConfigCommitPath );
    SysFreeString( bstrSectionName );
    SysFreeString( bstrConfigSource );
    SysFreeString( bstrConfigSourceAttr );


    // Uninitialize
    CoUninitialize();

    return 0;
};

要求

类型 说明
客户端 - 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
Header Ahadmin.h

另请参阅

IAppHostWritableAdminManager 接口