#include #define INITGUID // must be before iadmw.h #include // Interface header #include // MD_ & IIS_MD_ defines #define REASONABLE_TIMEOUT 1000 void ShowHelp(void); LPSTR StripWhitespace(LPSTR pszString); BOOL OpenMetabaseAndDoStuff(WCHAR * wszVDir, WCHAR * wszDir, int iTrans); BOOL GetVdirPhysicalPath(IMSAdminBase *pIMSAdminBase,WCHAR * wszVDir,WCHAR *wszStringPathToFill); BOOL AddVirtualDir(IMSAdminBase *pIMSAdminBase, WCHAR * wszVDir, WCHAR * wszDir); BOOL RemoveVirtualDir(IMSAdminBase *pIMSAdminBase, WCHAR * wszVDir); HRESULT LoadAllData(IMSAdminBase * pmb, METADATA_HANDLE hMetabase,WCHAR *subdir, BYTE **buf, DWORD *size,DWORD *count); HRESULT AddVirtualServer(UINT iServerNum, UINT iServerPort, WCHAR * wszDefaultVDirDir); HRESULT DelVirtualServer(UINT iServerNum); #define TRANS_ADD 0 #define TRANS_DEL 1 #define TRANS_PRINT_PATH 2 #define TRANS_ADD_VIRTUAL_SERVER 4 #define TRANS_DEL_VIRTUAL_SERVER 8 int __cdecl main( int argc, char *argv[] ) { BOOL fRet = FALSE; int argno; char * pArg = NULL; char * pCmdStart = NULL; WCHAR wszPrintString[MAX_PATH]; char szTempString[MAX_PATH]; int iGotParamS = FALSE; int iGotParamP = FALSE; int iGotParamV = FALSE; int iDoDelete = FALSE; int iDoWebPath = FALSE; int iTrans = 0; WCHAR wszDirPath[MAX_PATH]; WCHAR wszVDirName[MAX_PATH]; WCHAR wszTempString_S[MAX_PATH]; WCHAR wszTempString_P[MAX_PATH]; wszDirPath[0] = '\0'; wszVDirName[0] = '\0'; wszTempString_S[0] = '\0'; wszTempString_P[0] = '\0'; for(argno=1; argnoSaveData(); if( SUCCEEDED( hr )) { fRet = TRUE; } } if (TRUE == fRet) { wsprintf(wszPrintString,L"SUCCESS:removed vdir=%s\n", wszVDir); wprintf(wszPrintString); } else { wsprintf(wszPrintString,L"FAILED to remove vdir=%s, err=0x%x\n", wszVDir, hr); wprintf(wszPrintString); } break; case TRANS_ADD: if( AddVirtualDir( pIMSAdminBase, wszVDir, wszDir)) { hr = pIMSAdminBase->SaveData(); if( SUCCEEDED( hr )) { fRet = TRUE; } } if (TRUE == fRet) { wsprintf(wszPrintString,L"SUCCESS: %s=%s", wszVDir, wszDir); wprintf(wszPrintString); } else { wsprintf(wszPrintString,L"FAILED to set: %s=%s, err=0x%x", wszVDir, wszDir, hr); wprintf(wszPrintString); } break; default: WCHAR wszRootPath[MAX_PATH]; if (TRUE == GetVdirPhysicalPath(pIMSAdminBase,wszVDir,(WCHAR *) wszRootPath)) { fRet = TRUE; if (_wcsicmp(wszVDir, L"") == 0) { wsprintf(wszPrintString,L"/=%s", wszRootPath); } else { wsprintf(wszPrintString,L"%s=%s", wszVDir, wszRootPath); } wprintf(wszPrintString); } else { wprintf(L"FAILED to get root path"); } break; } if (pIMSAdminBase) { pIMSAdminBase->Release(); pIMSAdminBase = NULL; } CoUninitialize(); return fRet; } BOOL GetVdirPhysicalPath( IMSAdminBase *pIMSAdminBase, WCHAR * wszVDir, WCHAR *wszStringPathToFill ) { HRESULT hr; BOOL fRet = FALSE; METADATA_HANDLE hMetabase = NULL; // handle to metabase METADATA_RECORD mr; WCHAR szTmpData[MAX_PATH]; DWORD dwMDRequiredDataLen; // open key to ROOT on website #1 (default) hr = pIMSAdminBase->OpenKey(METADATA_MASTER_ROOT_HANDLE, L"/LM/W3SVC/1", METADATA_PERMISSION_READ, REASONABLE_TIMEOUT, &hMetabase); if( FAILED( hr )) { return FALSE; } // Get the physical path for the WWWROOT mr.dwMDIdentifier = MD_VR_PATH; mr.dwMDAttributes = 0; mr.dwMDUserType = IIS_MD_UT_FILE; mr.dwMDDataType = STRING_METADATA; mr.dwMDDataLen = sizeof( szTmpData ); mr.pbMDData = reinterpret_cast(szTmpData); // if nothing specified get the root. if (_wcsicmp(wszVDir, L"") == 0) { WCHAR wszTempDir[MAX_PATH]; wsprintf(wszTempDir,L"/ROOT/%s", wszVDir); hr = pIMSAdminBase->GetData( hMetabase, wszTempDir, &mr, &dwMDRequiredDataLen ); } else { hr = pIMSAdminBase->GetData( hMetabase, L"/ROOT", &mr, &dwMDRequiredDataLen ); } pIMSAdminBase->CloseKey( hMetabase ); if( SUCCEEDED( hr )) { wcscpy(wszStringPathToFill,szTmpData); fRet = TRUE; } pIMSAdminBase->CloseKey( hMetabase ); return fRet; } BOOL AddVirtualDir( IMSAdminBase *pIMSAdminBase, WCHAR * wszVDir, WCHAR * wszDir ) { HRESULT hr; BOOL fRet = FALSE; METADATA_HANDLE hMetabase = NULL; // handle to metabase WCHAR wszTempPath[MAX_PATH]; DWORD dwMDRequiredDataLen = 0; DWORD dwAccessPerm = 0; METADATA_RECORD mr; // Attempt to open the virtual dir set on Web server #1 (default server) hr = pIMSAdminBase->OpenKey( METADATA_MASTER_ROOT_HANDLE, L"/LM/W3SVC/1/ROOT", METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE, REASONABLE_TIMEOUT, &hMetabase ); // Create the key if it does not exist. if( FAILED( hr )) { return FALSE; } fRet = TRUE; mr.dwMDIdentifier = MD_VR_PATH; mr.dwMDAttributes = 0; mr.dwMDUserType = IIS_MD_UT_FILE; mr.dwMDDataType = STRING_METADATA; mr.dwMDDataLen = sizeof( wszTempPath ); mr.pbMDData = reinterpret_cast(wszTempPath); // see if MD_VR_PATH exists. hr = pIMSAdminBase->GetData( hMetabase, wszVDir, &mr, &dwMDRequiredDataLen ); if( FAILED( hr )) { fRet = FALSE; if( hr == MD_ERROR_DATA_NOT_FOUND || HRESULT_CODE(hr) == ERROR_PATH_NOT_FOUND ) { // Write both the key and the values if GetData() failed with any of the two errors. pIMSAdminBase->AddKey( hMetabase, wszVDir ); mr.dwMDIdentifier = MD_VR_PATH; mr.dwMDAttributes = METADATA_INHERIT; mr.dwMDUserType = IIS_MD_UT_FILE; mr.dwMDDataType = STRING_METADATA; mr.dwMDDataLen = (wcslen(wszDir) + 1) * sizeof(WCHAR); mr.pbMDData = reinterpret_cast(wszDir); // Write MD_VR_PATH value hr = pIMSAdminBase->SetData( hMetabase, wszVDir, &mr ); fRet = SUCCEEDED( hr ); // Set the default authentication method if( fRet ) { DWORD dwAuthorization = MD_AUTH_NT; // NTLM only. mr.dwMDIdentifier = MD_AUTHORIZATION; mr.dwMDAttributes = METADATA_INHERIT; // need to inherit so that all subdirs are also protected. mr.dwMDUserType = IIS_MD_UT_FILE; mr.dwMDDataType = DWORD_METADATA; mr.dwMDDataLen = sizeof(DWORD); mr.pbMDData = reinterpret_cast(&dwAuthorization); // Write MD_AUTHORIZATION value hr = pIMSAdminBase->SetData( hMetabase, wszVDir, &mr ); fRet = SUCCEEDED( hr ); } } } // In the following, do the stuff that we always want to do to the virtual dir, regardless of Admin's setting. if( fRet ) { dwAccessPerm = MD_ACCESS_READ | MD_ACCESS_SCRIPT; mr.dwMDIdentifier = MD_ACCESS_PERM; mr.dwMDAttributes = METADATA_INHERIT; // Make it inheritable so all subdirectories will have the same rights. mr.dwMDUserType = IIS_MD_UT_FILE; mr.dwMDDataType = DWORD_METADATA; mr.dwMDDataLen = sizeof(DWORD); mr.pbMDData = reinterpret_cast(&dwAccessPerm); // Write MD_ACCESS_PERM value hr = pIMSAdminBase->SetData( hMetabase, wszVDir, &mr ); fRet = SUCCEEDED( hr ); } if( fRet ) { PWCHAR szDefLoadFile = L"Default.htm,Default.asp"; mr.dwMDIdentifier = MD_DEFAULT_LOAD_FILE; mr.dwMDAttributes = 0; // no need for inheritence mr.dwMDUserType = IIS_MD_UT_FILE; mr.dwMDDataType = STRING_METADATA; mr.dwMDDataLen = (wcslen(szDefLoadFile) + 1) * sizeof(WCHAR); mr.pbMDData = reinterpret_cast(szDefLoadFile); // Write MD_DEFAULT_LOAD_FILE value hr = pIMSAdminBase->SetData( hMetabase, wszVDir, &mr ); fRet = SUCCEEDED( hr ); } if( fRet ) { PWCHAR wszKeyType = IIS_CLASS_WEB_VDIR_W; mr.dwMDIdentifier = MD_KEY_TYPE; mr.dwMDAttributes = 0; // no need for inheritence mr.dwMDUserType = IIS_MD_UT_SERVER; mr.dwMDDataType = STRING_METADATA; mr.dwMDDataLen = (wcslen(wszKeyType) + 1) * sizeof(WCHAR); mr.pbMDData = reinterpret_cast(wszKeyType); // Write MD_DEFAULT_LOAD_FILE value hr = pIMSAdminBase->SetData( hMetabase, wszVDir, &mr ); fRet = SUCCEEDED( hr ); } pIMSAdminBase->CloseKey( hMetabase ); return fRet; } BOOL RemoveVirtualDir( IMSAdminBase *pIMSAdminBase, WCHAR * wszVDir ) { METADATA_HANDLE hMetabase = NULL; // handle to metabase HRESULT hr; // Attempt to open the virtual dir set on Web server #1 (default server) hr = pIMSAdminBase->OpenKey( METADATA_MASTER_ROOT_HANDLE, L"/LM/W3SVC/1/ROOT", METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE, REASONABLE_TIMEOUT, &hMetabase ); if( FAILED( hr )) { return FALSE; } // We don't check the return value since the key may already // not exist and we could get an error for that reason. pIMSAdminBase->DeleteKey( hMetabase, wszVDir ); pIMSAdminBase->CloseKey( hMetabase ); return TRUE; } HRESULT LoadAllData(IMSAdminBase * pmb, METADATA_HANDLE hMetabase, WCHAR *subdir, BYTE **buf, DWORD *size, DWORD *count) { DWORD dataSet; DWORD neededSize; HRESULT hr; // // Try to get the property names. // hr = pmb->GetAllData(hMetabase, subdir, METADATA_NO_ATTRIBUTES, ALL_METADATA, ALL_METADATA, count, &dataSet, *size, *buf, &neededSize); if (!SUCCEEDED(hr)) { DWORD code = ERROR_INSUFFICIENT_BUFFER; if (hr == RETURNCODETOHRESULT(ERROR_INSUFFICIENT_BUFFER)) { delete *buf; *buf = 0; *size = neededSize; *buf = new BYTE[neededSize]; hr = pmb->GetAllData(hMetabase, subdir, METADATA_NO_ATTRIBUTES, ALL_METADATA, ALL_METADATA, count, &dataSet, *size, *buf, &neededSize); } } return hr; } const DWORD getAllBufSize = 4096*2; HRESULT OpenMetabaseAndGetAllData(void) { HRESULT hr = E_FAIL; IMSAdminBase *pIMSAdminBase = NULL; // Metabase interface pointer WCHAR wszPrintString[MAX_PATH + MAX_PATH]; METADATA_HANDLE hMetabase = NULL; // handle to metabase DWORD bufSize = getAllBufSize; BYTE *buf = new BYTE[bufSize]; DWORD count=0; DWORD linesize =0; BYTE *pBuf1=NULL; BYTE *pBuf2=NULL; if( FAILED (CoInitializeEx( NULL, COINIT_MULTITHREADED )) || FAILED (::CoCreateInstance(CLSID_MSAdminBase, NULL, CLSCTX_ALL, IID_IMSAdminBase, (void **)&pIMSAdminBase))) { wprintf(L"CoCreateInstance. FAILED. code=0x%x\n",hr); return hr; } // Attempt to open the virtual dir set on Web server #1 (default server) hr = pIMSAdminBase->OpenKey( METADATA_MASTER_ROOT_HANDLE, L"/Schema/Properties", METADATA_PERMISSION_READ, REASONABLE_TIMEOUT, &hMetabase ); if( FAILED( hr )) { wprintf(L"pIMSAdminBase->OpenKey. FAILED. code=0x%x\n",hr); goto OpenMetabaseAndGetAllData_Exit; } hr = LoadAllData(pIMSAdminBase, hMetabase, L"Names", &buf, &bufSize, &count); if( FAILED( hr )) { wprintf(L"LoadAllData: FAILED. code=0x%x\n",hr); goto OpenMetabaseAndGetAllData_Exit; } wprintf(L"LoadAllData: Succeeded. bufSize=0x%x, count=0x%x, buf=%p, end of buf=%p\n",bufSize,count,buf,buf+bufSize); wprintf(L"Here is the last 1000 bytes, that the client received.\n"); linesize = 0; pBuf1 = buf+bufSize - 1000; for (int i=0;pBuf1= 16) { linesize=0; wprintf(L"\n"); } } wprintf(L"\n"); hr = ERROR_SUCCESS; OpenMetabaseAndGetAllData_Exit: if (pIMSAdminBase) { pIMSAdminBase->Release(); pIMSAdminBase = NULL; } CoUninitialize(); return hr; } // Calculate the size of a Multi-String in WCHAR, including the ending 2 '\0's. int GetMultiStrSize(LPWSTR p) { int c = 0; while (1) { if (*p) { p++; c++; } else { c++; if (*(p+1)) { p++; } else { c++; break; } } } return c; } HRESULT DelVirtualServer(UINT iServerNum) { HRESULT hr = E_FAIL; return hr; } // iServerNum the virtual server number // iServerPort the virtual server port (port 80 is the default site's port,so you can't use this and you can't use one that is already in use) // wszDir the physical directory where the default site is located HRESULT AddVirtualServer(UINT iServerNum, UINT iServerPort, WCHAR * wszDefaultVDirDir) { HRESULT hr = E_FAIL; IMSAdminBase *pIMSAdminBase = NULL; // Metabase interface pointer METADATA_HANDLE hMetabase = NULL; // handle to metabase METADATA_RECORD mr; WCHAR wszMetabasePath[_MAX_PATH]; WCHAR wszMetabasePathRoot[10]; WCHAR wszData[_MAX_PATH]; DWORD dwData = 0; METADATA_HANDLE hKeyBase = METADATA_MASTER_ROOT_HANDLE; if( FAILED (CoInitializeEx( NULL, COINIT_MULTITHREADED )) || FAILED (::CoCreateInstance(CLSID_MSAdminBase, NULL, CLSCTX_ALL, IID_IMSAdminBase, (void **)&pIMSAdminBase))) { wprintf(L"CoCreateInstance. FAILED. code=0x%x\n",hr); return hr; } // Create the new node wsprintf(wszMetabasePath,L"LM/W3SVC/%i",iServerNum); // try to open the specified metabase node, it might already exist hr = pIMSAdminBase->OpenKey(hKeyBase, wszMetabasePath, METADATA_PERMISSION_READ, REASONABLE_TIMEOUT, &hMetabase); if (hr == RETURNCODETOHRESULT(ERROR_PATH_NOT_FOUND)) { hr = pIMSAdminBase->CloseKey(hMetabase); // open the metabase root handle hr = pIMSAdminBase->OpenKey(hKeyBase, L"", METADATA_PERMISSION_WRITE | METADATA_PERMISSION_READ, REASONABLE_TIMEOUT,&hMetabase); if( FAILED( hr )) { // if we can't even open the root handle, then we're pretty hosed wprintf(L"1OpenKey. FAILED. code=0x%x\n",hr); goto AddVirtualServer_Exit; } // and add our node hr = pIMSAdminBase->AddKey(hMetabase, wszMetabasePath); if (FAILED(hr)) { wprintf(L"AddKey. FAILED. code=0x%x\n",hr); pIMSAdminBase->CloseKey(hMetabase); goto AddVirtualServer_Exit; } else { hr = pIMSAdminBase->CloseKey(hMetabase); if (FAILED(hr)) { goto AddVirtualServer_Exit; } else { // open it again hr = pIMSAdminBase->OpenKey(hKeyBase, wszMetabasePath, METADATA_PERMISSION_WRITE | METADATA_PERMISSION_READ, REASONABLE_TIMEOUT, &hMetabase); if (FAILED(hr)) { wprintf(L"2OpenKey. FAILED. code=0x%x\n",hr); pIMSAdminBase->CloseKey(hMetabase); goto AddVirtualServer_Exit; } } } } else { if (FAILED(hr)) { wprintf(L"3OpenKey. FAILED. code=0x%x\n",hr); goto AddVirtualServer_Exit; } else { // we were able to open the path, so it must already exist! hr = ERROR_ALREADY_EXISTS; pIMSAdminBase->CloseKey(hMetabase); goto AddVirtualServer_Exit; } } // We should have a brand new Key now... // // Create stuff in the node of this path! // // // /LM/W3SVC/1/KeyType // memset( (PVOID)wszData, 0, sizeof(wszData)); wcscpy(wszData,IIS_CLASS_WEB_SERVER_W); mr.dwMDIdentifier = MD_KEY_TYPE; mr.dwMDAttributes = 0; // no need for inheritence mr.dwMDUserType = IIS_MD_UT_SERVER; mr.dwMDDataType = STRING_METADATA; mr.dwMDDataLen = (wcslen(wszData) + 1) * sizeof(WCHAR); mr.pbMDData = reinterpret_cast(wszData); hr = pIMSAdminBase->SetData( hMetabase, L"", &mr ); if (FAILED(hr)) { wprintf(L"SetData[MD_KEY_TYPE]. FAILED. code=0x%x\n",hr); } // // /W3SVC/1/ServerBindings // memset( (PVOID)wszData, 0, sizeof(wszData)); wsprintf(wszData, L":%d:", iServerPort); mr.dwMDIdentifier = MD_SERVER_BINDINGS; mr.dwMDAttributes = METADATA_INHERIT; mr.dwMDUserType = IIS_MD_UT_SERVER; mr.dwMDDataType = MULTISZ_METADATA; mr.dwMDDataLen = GetMultiStrSize(wszData) * sizeof(WCHAR); mr.pbMDData = reinterpret_cast(wszData); hr = pIMSAdminBase->SetData( hMetabase, L"", &mr ); if (FAILED(hr)) { wprintf(L"SetData[MD_SERVER_BINDINGS]. FAILED. code=0x%x\n",hr); } // // /W3SVC/1/SecureBindings // memset( (PVOID)wszData, 0, sizeof(wszData)); wcscpy(wszData, L" "); mr.dwMDIdentifier = MD_SECURE_BINDINGS; mr.dwMDAttributes = METADATA_INHERIT; mr.dwMDUserType = IIS_MD_UT_SERVER; mr.dwMDDataType = MULTISZ_METADATA; mr.dwMDDataLen = GetMultiStrSize(wszData) * sizeof(WCHAR); mr.pbMDData = reinterpret_cast(wszData); hr = pIMSAdminBase->SetData( hMetabase, L"", &mr ); if (FAILED(hr)) { wprintf(L"SetData[MD_SECURE_BINDINGS]. FAILED. code=0x%x\n",hr); } // // Create stuff in the /Root node of this path! // wcscpy(wszMetabasePathRoot, L"/Root"); wcscpy(wszData,IIS_CLASS_WEB_VDIR_W); // W3SVC/3/Root/KeyType mr.dwMDIdentifier = MD_KEY_TYPE; mr.dwMDAttributes = 0; // no need for inheritence mr.dwMDUserType = IIS_MD_UT_SERVER; mr.dwMDDataType = STRING_METADATA; mr.dwMDDataLen = (wcslen(wszData) + 1) * sizeof(WCHAR); mr.pbMDData = reinterpret_cast(wszData); hr = pIMSAdminBase->SetData( hMetabase, wszMetabasePathRoot, &mr ); if (FAILED(hr)) { wprintf(L"SetData[MD_KEY_TYPE]. FAILED. code=0x%x\n",hr); } // W3SVC/3/Root/VrPath mr.dwMDIdentifier = MD_VR_PATH; mr.dwMDAttributes = METADATA_INHERIT; mr.dwMDUserType = IIS_MD_UT_FILE; mr.dwMDDataType = STRING_METADATA; mr.dwMDDataLen = (wcslen(wszDefaultVDirDir) + 1) * sizeof(WCHAR); mr.pbMDData = reinterpret_cast(wszDefaultVDirDir); hr = pIMSAdminBase->SetData( hMetabase, wszMetabasePathRoot, &mr ); if (FAILED(hr)) { wprintf(L"SetData[MD_VR_PATH]. FAILED. code=0x%x\n",hr); } // W3SVC/3/Root/Authorizaton dwData = MD_AUTH_ANONYMOUS | MD_AUTH_NT; mr.dwMDIdentifier = MD_AUTHORIZATION; mr.dwMDAttributes = METADATA_INHERIT; mr.dwMDUserType = IIS_MD_UT_FILE; mr.dwMDDataType = DWORD_METADATA; mr.dwMDDataLen = sizeof(DWORD); mr.pbMDData = reinterpret_cast(&dwData); hr = pIMSAdminBase->SetData( hMetabase, wszMetabasePathRoot, &mr ); if (FAILED(hr)) { wprintf(L"SetData[MD_AUTHORIZATION]. FAILED. code=0x%x\n",hr); } // W3SVC/3/Root/AccessPerm dwData = MD_ACCESS_SCRIPT | MD_ACCESS_READ; mr.dwMDIdentifier = MD_ACCESS_PERM; mr.dwMDAttributes = METADATA_INHERIT; mr.dwMDUserType = IIS_MD_UT_FILE; mr.dwMDDataType = DWORD_METADATA; mr.dwMDDataLen = sizeof(DWORD); mr.pbMDData = reinterpret_cast(&dwData); hr = pIMSAdminBase->SetData( hMetabase, wszMetabasePathRoot, &mr ); if (FAILED(hr)) { wprintf(L"SetData[MD_ACCESS_PERM]. FAILED. code=0x%x\n",hr); } // W3SVC/3/Root/DirectoryBrowsing dwData = MD_DIRBROW_SHOW_DATE | MD_DIRBROW_SHOW_TIME | MD_DIRBROW_SHOW_SIZE | MD_DIRBROW_SHOW_EXTENSION | MD_DIRBROW_LONG_DATE | MD_DIRBROW_LOADDEFAULT; // | MD_DIRBROW_ENABLED; mr.dwMDIdentifier = MD_DIRECTORY_BROWSING; mr.dwMDAttributes = METADATA_INHERIT; mr.dwMDUserType = IIS_MD_UT_FILE; mr.dwMDDataType = DWORD_METADATA; mr.dwMDDataLen = sizeof(DWORD); mr.pbMDData = reinterpret_cast(&dwData); hr = pIMSAdminBase->SetData( hMetabase, wszMetabasePathRoot, &mr ); if (FAILED(hr)) { wprintf(L"SetData[MD_DIRECTORY_BROWSING]. FAILED. code=0x%x\n",hr); } /* dwData = 0; mr.dwMDIdentifier = MD_SERVER_AUTOSTART; mr.dwMDAttributes = METADATA_INHERIT; mr.dwMDUserType = IIS_MD_UT_FILE; mr.dwMDDataType = DWORD_METADATA; mr.dwMDDataLen = sizeof(DWORD); mr.pbMDData = reinterpret_cast(&dwData); hr = pIMSAdminBase->SetData( hMetabase, wszMetabasePathRoot, &mr ); if (FAILED(hr)) { wprintf(L"SetData[MD_SERVER_AUTOSTART]. FAILED. code=0x%x\n",hr); } */ pIMSAdminBase->CloseKey(hMetabase); AddVirtualServer_Exit: if (pIMSAdminBase) { pIMSAdminBase->Release(); pIMSAdminBase = NULL; } CoUninitialize(); return hr; }