Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Ottiene la proprietà con l'indice o il nome della proprietà richiesti nell'insieme.
Sintassi
HRESULT get_Item(
[in] VARIANT cIndex,
[out,
retval] IAppHostProperty** ppProperty
);
Parametri
cIndex
Oggetto VARIANT contenente l'indice o il nome della proprietà dell'elemento da recuperare dalla raccolta.
ppProperty
Puntatore a un puntatore per un'interfaccia IAppHostProperty .
Valore restituito
Oggetto HRESULT. I valori possibili includono, ma non sono limitati a, quelli indicati nella tabella seguente.
| Valore | Descrizione |
|---|---|
| S_OK | Indica che l'operazione è riuscita. |
| ERROR_INVALID_INDEX | Indica che la proprietà richiesta non è stata trovata. |
Esempio
Nell'esempio di codice seguente viene illustrato come usare l'interfaccia IAppHostPropertyCollection per accedere alla enabled proprietà della defaultDocument sezione di configurazione.
#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;
};
Requisiti
| Tipo | Descrizione |
|---|---|
| Client | - IIS 7.0 in Windows Vista - IIS 7.5 in Windows 7 - IIS 8.0 in Windows 8 - IIS 10.0 in Windows 10 |
| Server | - IIS 7.0 in Windows Server 2008 - IIS 7.5 in Windows Server 2008 R2 - IIS 8.0 in Windows Server 2012 - IIS 8.5 in Windows Server 2012 R2 - IIS 10.0 in Windows Server 2016 |
| Prodotto | - 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 |
| Intestazione | Ahadmin.h |