就是iis里面有很多站点,以不同的port号标识,如:
http://10.1.100.100:8000
http://10.1.100.100:8001
http://10.1.100.100:8002
http://10.1.100.100:8003
等等我如何得到我的iis里的这些站点网址,并保存在字符串里?用vc来实现。希望大家帮忙~
http://10.1.100.100:8000
http://10.1.100.100:8001
http://10.1.100.100:8002
http://10.1.100.100:8003
等等我如何得到我的iis里的这些站点网址,并保存在字符串里?用vc来实现。希望大家帮忙~
#include <stdio.h>
#include "IAds.h"
#include "Adshlp.h"
#include "activeds.h"
#include <COMDEF.h>int main()
{
IADsContainer* pContainer = NULL;
HRESULT hr;
bool bCoInit = false; // Initializing the COM library on the current thread. It should be always
// initialized, a failed result could be due to the previous initializing.
hr = ::CoInitialize(NULL);
if SUCCEEDED(hr)
bCoInit = true;
// Get object IIS web server object
hr = ADsGetObject(L"IIS://localhost/W3svc" ,IID_IADsContainer,(void**)&pContainer);
if FAILED(hr)
{
printf("Error in get web3svc object\n");
return -1;
} // Get an enumerator to iterate through the possible web server list
IUnknown *pUnk;
hr = pContainer->get__NewEnum(&pUnk);
pContainer->Release(); // No need for IAdsContainer, free it before too later.
if FAILED(hr)
{
printf("Error in getting the enumeration\n");
return -2;
} // From IUnknown interface, query to get the EnumVARIANT interface
IEnumVARIANT *pEnum;
hr = pUnk->QueryInterface(IID_IEnumVARIANT,(void**)&pEnum);
pUnk->Release(); // No need for IUnknown, free it before too later.
if FAILED(hr)
{
printf("Error in getting the enumeration variant\n");
return -3;
} // Finally, ready for enumerating the IIS virtual web server.
BSTR bstr;
VARIANT var;
IADs *pADs;
ULONG lFetch;
IDispatch *pDisp; // Initialise the variant
VariantInit(&var); // Get the 1st
hr = pEnum->Next(1, &var, &lFetch);
while(hr == S_OK)
{
if (lFetch == 1)
{
// Need the IADs interface, so use QueryInterface again
pDisp = V_DISPATCH(&var);
pDisp->QueryInterface(IID_IADs, (void**)&pADs); // Get the name of the group so that we can display it
// The query result will be something like:
// Filters -- W3svc/Filters
// Info -- W3Svc/Info
// 1 -- W3Svc/1
// 2 -- W3Svc/2
// ...
// n -- W3Svc/n
//
// Note:
// The W3Svc/n, wile n [1~N] is the virtual web server in format:
//
// IP:Port:Host Name
//
pADs->get_Name(&bstr);
//printf("Group: %S\n",bstr); // <--- debug printing. //---Get the virtual web site info---
VARIANT var1;
VariantInit(&var1);
HRESULT hr1; // Get ServerBindings, the string format is IP:Port:HostName
hr1 = pADs->Get(L"ServerBindings", &var1 ); // if not W3Svc/n, it will fail.
if ( SUCCEEDED(hr1) )
{
LONG lstart, lend;
SAFEARRAY *sa = V_ARRAY(&var1);
VARIANT varItem;
// Get the lower and upper bound
hr1 = SafeArrayGetLBound( sa, 1, &lstart );
hr1 = SafeArrayGetUBound( sa, 1, &lend );
VariantInit(&varItem); for (long idx = lstart; idx <= lend; idx++)
{
hr1 = SafeArrayGetElement( sa, &idx, &varItem );
printf(" %S\n", V_BSTR(&varItem)); // <--- output, customize here/
VariantClear(&varItem);
}
VariantClear(&var1);
} //end Get(ServerBindings) //---Done with the virtual web site info--- //clear up IAds
if (pADs)
pADs->Release();
// Release the string because we don't need it any more
SysFreeString(bstr);
}
VariantClear(&var);
// Get the next one in the group
hr = pEnum->Next(1, &var, &lFetch);
};
// Clear up the enumerator
if (pEnum)
pEnum->Release(); //Courtesy balance, uninitialise the COM interface
if (bCoInit)
::CoUninitialize(); return 0;
}
http://forum.3382.net/u/topic_show.cgi?id=209609&h=1&bpg=1&age=0
大家可以去看看
也贴在这里,可以供别人参考问题是,分数我给谁呢?