How to I obtain an IIS Virtual DIrectory name from an IIS metabase path in c++

China☆狼群 提交于 2019-12-11 17:54:32

问题


I have the following metabase path:

/lm/w3svc/1/root/foo

which I can see in IIS manager maps to the virtual directory:

Default Web Site/foo

How can I determine the virtual directory name from the metabase path in c++?


回答1:


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;
}


来源:https://stackoverflow.com/questions/4710187/how-to-i-obtain-an-iis-virtual-directory-name-from-an-iis-metabase-path-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!