查询 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 应用程序中运行时正常。
任何想法?