Posted on 2009-10-05 19:14
S.l.e!ep.¢% 阅读(678)
评论(1) 编辑 收藏 引用 所属分类:
COM
#include <iostream>
#include <objbase.h>
#include <initguid.h>
#include <comutil.h>
#include <Iads.h>
#include <Adshlp.h>
#include <IIIS.h>
#import "adsiis.dll" raw_interfaces_only named_guids
#pragma comment(lib,"adsiid.lib")
#pragma comment(lib,"ActiveDS.lib")
#pragma comment(lib,"comsupp.lib")
int main()
{
IADsContainer* iContainer;
IADs* iAds;
IISIPSecurity *iIPSec=NULL;
if(ADsGetObject(L"IIS://localhost/w3svc",IID_IADsContainer,(void**)&iContainer)!=S_OK)
{
return false;
}
if(iContainer->GetObject(_bstr_t("IIsWebServer"),_bstr_t("1"),(IDispatch**)&iAds)!=S_OK)
{
return false;
}
if(iAds->QueryInterface(IID_IISIPSecurity,(void**)&iIPSec)!=S_OK)
{
return false;
}
if(iIPSec->put_IPDeny(_variant_t("192.1.1.1,255.255.255.0"))!=S_OK)
{
return false;
}
else if(iAds->SetInfo()==S_OK)
{
return true;
}
return 0;
}