0

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++?

Kev
  • 118,037
  • 53
  • 300
  • 385
deltanine
  • 1,166
  • 1
  • 13
  • 25
  • If you already know the metabase path then the virtual directory will be foo. Maybe I'm missing something? – Kev Jan 18 '11 at 01:08
  • Yea, I wan't to know the full path to the virtual directory, which is something like: "Default Web Site/foo". Thats only if someone hasn't renamed "Default Web Site" to something else. Anyway, I found a solution, you need to query the server comment field from the metabase for the key "/lm/w3svc/1" to find the name of the default web site. – deltanine Jan 19 '11 at 21:34

1 Answers1

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;
}
deltanine
  • 1,166
  • 1
  • 13
  • 25