Catatan
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba masuk atau mengubah direktori.
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba mengubah direktori.
Mendapatkan bagian konfigurasi IIS 7 yang memiliki nama dan jalur konfigurasi yang diminta.
Sintaks
HRESULT GetAdminSection(
[in,
string] BSTR bstrSectionName,
[in,
string] BSTR bstrPath,
[out,
retval] IAppHostElement** ppAdminSection
);
Parameter
bstrSectionName
BSTR yang berisi jalur ke nama bagian yang valid dalam sistem konfigurasi.
bstrPath
BSTR yang berisi jalur sistem konfigurasi.
ppAdminSection
Pointer ke pointer untuk antarmuka IAppHostElement .
Tampilkan Nilai
Sebuah HRESULT. Nilai yang mungkin termasuk, tetapi tidak terbatas pada, yang ada dalam tabel berikut.
| Nilai | Deskripsi |
|---|---|
| S_OK | Menunjukkan bahwa operasi berhasil. |
| ERROR_INVALID_DATA | Menunjukkan bahwa data tidak valid. |
| ERROR_FILE_NOT_FOUND | Menunjukkan bahwa jalur yang diminta tidak ditemukan. |
| ERROR_INVALID_PARAMETER | Menunjukkan bahwa parameter salah. |
| E_ACCESSDENIED | Menunjukkan bahwa operasi tidak berhasil karena pembatasan akses. |
Keterangan
Untuk jalur konfigurasi tertentu, nilai pengembalian metode ini mewakili nilai terkait dalam kumpulan konfigurasi yang digabungkan secara hierarkis. Untuk mengatur jalur konfigurasi, gunakan bstrPath parameter metode ini.
Contoh
Contoh kode berikut menggunakan antarmuka IAppHostAdminManager untuk mendapatkan semua elemen turunan gabungan untuk system.webServer/asp bagian konfigurasi di jalur konfigurasi MACHINE/WEBROOT/APPHOST.
#pragma once
#include <stdio.h>
#include <string.h>
#include <ahadmin.h>
int main()
{
IAppHostAdminManager * pMgr = NULL;
IAppHostElement * pParentElem = NULL;
IAppHostChildElementCollection * pChildElems = NULL;
IAppHostElement * pChildElem = NULL;
HRESULT hr = S_OK;
BSTR bstrSectionName = SysAllocString( L"system.webServer/asp" );
BSTR bstrChildElemName = NULL;
DWORD dwElementCount = 0;
// Initialize
hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
if ( FAILED( hr ) )
{
printf_s( "ERROR: Unable to initialize\n" );
goto exit;
}
// Create an admin manager
hr = CoCreateInstance( __uuidof( AppHostAdminManager ), NULL,
CLSCTX_INPROC_SERVER,
__uuidof( IAppHostAdminManager ), (void**) &pMgr );
if( FAILED( hr ) )
{
printf_s( "ERROR: Unable to create an IAppHostAdminManager\n" );
goto exit;
}
// Get the admin section
wprintf_s( L"Getting %s\n", bstrSectionName );
hr = pMgr->GetAdminSection( bstrSectionName, NULL, &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 asp configuration section.\n" );
}
goto exit;
}
// Get the child elements
wprintf_s( L"Getting child elements\n" );
hr = pParentElem->get_ChildElements( &pChildElems );
if ( FAILED( hr ) || ( &pChildElems == NULL ) )
{
wprintf_s( L"ERROR: Unable to access child elements of %s\n", bstrSectionName );
goto exit;
}
// Loop through child elements
wprintf_s( L"Seaching for child elements of %s\n", bstrSectionName );
hr = pChildElems->get_Count( &dwElementCount );
for( USHORT i = 0; i < dwElementCount; i++ )
{
VARIANT vtItemIndex;
vtItemIndex.vt = VT_I2;
vtItemIndex.iVal = i;
// Get the section group
hr = pChildElems->get_Item( vtItemIndex, &pChildElem );
if ( FAILED( hr ) || ( &pChildElem == NULL ) )
{
wprintf_s( L"ERROR: Unable to find child element: %d\n", i );
goto loop_cleanup;
}
// Get the name
hr = pChildElem->get_Name ( &bstrChildElemName );
if ( FAILED( hr ) )
{
wprintf_s( L"ERROR: Unable to get child element name.\n" );
goto loop_cleanup;
}
wprintf_s( L"\tChild element found: %s\n", bstrChildElemName );
loop_cleanup:
if ( pChildElem != NULL )
{
pChildElem->Release();
pChildElem = NULL;
}
SysFreeString( bstrChildElemName );
}
exit:
// Exiting / Unwinding
if ( pChildElems != NULL )
{
pChildElems->Release();
pChildElems = NULL;
}
if ( pParentElem != NULL )
{
pParentElem->Release();
pParentElem = NULL;
}
if ( pMgr != NULL )
{
pMgr->Release();
pMgr = NULL;
}
SysFreeString( bstrChildElemName );
SysFreeString( bstrSectionName );
// Uninitialize
CoUninitialize();
return 0;
};
Persyaratan
| Jenis | Deskripsi |
|---|---|
| Klien | - IIS 7.0 di Windows Vista - IIS 7.5 di Windows 7 - IIS 8.0 di Windows 8 - IIS 10.0 pada Windows 10 |
| Server | - IIS 7.0 di Windows Server 2008 - IIS 7.5 di Windows Server 2008 R2 - IIS 8.0 di Windows Server 2012 - IIS 8.5 di Windows Server 2012 R2 - IIS 10.0 di Windows Server 2016 |
| Produk | - 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 |
Lihat juga
Antarmuka IAppHostAdminManager
Metode IAppHostConfigFile::GetAdminSection