0

我有以下元数据库路径:

/lm/w3svc/1/root/foo

我可以在 IIS 管理器中看到映射到虚拟目录:

Default Web Site/foo

如何从 C++ 中的元数据库路径确定虚拟目录名称?

4

1 回答 1

0
HRESULT CAeXMSAdminBasePtr::GetVirtualDirectoryName( LPCWSTR szMetaPath, LPWSTR  szVirtualDirectoryName, DWORD dwVirtualDirectoryNameLen )
{
    HRESULT hr = S_OK;
    METADATA_RECORD mdRecord;   
    memset(&mdRecord, 0, sizeof(METADATA_RECORD));

    METADATA_HANDLE hMetaData = NULL;
    IMSAdminBasePtr spAdminBase

    try
    {

        spAdminBase.CoCreateInstance(CLSID_MSAdminBase);

        spAdminBase->OpenKey(METADATA_MASTER_ROOT_HANDLE, szMetaPath, METADATA_PERMISSION_READ, g_dwCommandTimeOut, hMetaData);

        //
        // Get Server Comment field aka Web Site Name
        //
        MD_SET_DATA_RECORD(&mdRecord, MD_SERVER_COMMENT, METADATA_NO_ATTRIBUTES, IIS_MD_UT_SERVER, ALL_METADATA , dwVirtualDirectoryNameLen*sizeof(WCHAR), szVirtualDirectoryName );
        spAdminBase->GetData(hMetaData, L"", mdRecord, dwVirtualDirectoryNameLen ); 
        if( hMetaData != NULL )
        {
            spAdminBase->CloseKey(hMetaData);
        }
    }
    catch(...)
    {
        hr = E_FAIL;
        if( hMetaData != NULL )
        {
            spAdminBase->CloseKey(hMetaData);
        }
        // Propogate exception to caller
        throw;
    }

    return hr;
}
于 2011-01-19T21:59:51.027 回答