iis7 構成データをクエリすると、ワーカー プロセス内で実行すると失敗し、コンソール アプリケーションでは問題ありません。
COSERVERINFO csiMachineName;
csiMachineName.pAuthInfo = NULL;
csiMachineName.dwReserved1 = 0;
csiMachineName.dwReserved2 = 0;
csiMachineName.pwszName = L"localhost";
hr = CoGetClassObject(
__uuidof( AppHostAdminManager ),
CLSCTX_SERVER,
&csiMachineName,
IID_IClassFactory,
(void**) &(pClassFactory.GetInterfacePtr()));
hr = pClassFactory->CreateInstance(
NULL, __uuidof( IAppHostAdminManager ), (void **) &(iisAdmin.GetInterfacePtr()));
bstr_t bstrSectionName("system.applicationHost/applicationPools");
bstr_t bstrPath("MACHINE/WEBROOT/APPHOST");
hr = iisAdmin->GetAdminSection(bstrSectionName, bstrPath, &(sitesElement.GetInterfacePtr()) );
hr = sitesElement->get_Collection(&(sitesElementCollection.GetInterfacePtr()));
DWORD sitesCount = 0;
hr = sitesElementCollection->get_Count(&sitesCount);
sitesCount
このコードがIISモジュールで実行されている場合は0ですが、Windowsアプリケーションで実行されている場合は問題ありません。
何か案が?