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

1

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

Schlessel answered 17/1, 2011 at 5:6 Comment(2)
If you already know the metabase path then the virtual directory will be foo. Maybe I'm missing something?Stalactite
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.Schlessel
S
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;
}
Schlessel answered 19/1, 2011 at 21:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.