小弟需要使用ABO或ADSI建立website,但用c++实现的文档很少,哪位高手能指点一下啊!需要建立IIsWebServer和IIsWebVirtualDir,谢谢!

解决方案 »

  1.   

    //VC6.0+SP5, SDK200210, windows 2000 server
    #include <windows.h>
    #include <Iads.h>
    #include <comdef.h>
    #include <tchar.h>
    #include <stdio.h>
    #include <Adshlp.h>
    #pragma comment(lib,"ActiveDS")
    #pragma comment(lib,"adsiid")
    BOOL CreateWebServer(LPCTSTR bindaddress,LPCTSTR domain,LPCTSTR DiskPath);
    void main()
    {
    CoInitialize(NULL);
    if(TRUE==CreateWebServer(_T("192.168.0.224:80"),_T("www.masterz.com"),_T("d:\\tmp")))
    printf("create site ok\n");
    else
    printf("create site failed\n");
    CoUninitialize();
    }
    BOOL CreateWebServer(LPCTSTR bindaddress,LPCTSTR domain,LPCTSTR pathname)
    {
    if(bindaddress==NULL||NULL==domain||NULL==pathname)
    return FALSE;
    IADsContainer *pCont=NULL;
    IADs* pAds=NULL;
    IADs* pVrAds=NULL;
    IADsServiceOperations *pSrvOp=NULL;
    IDispatch *pDisp = NULL;
    IDispatch *pVrDisp = NULL;
    _bstr_t WNumer="123";
    _bstr_t newBindings=_bstr_t(bindaddress)+":"+domain;
    HRESULT hr;
    if(ADsGetObject(L"IIS://localhost/w3svc",IID_IADsContainer,(void**)&pCont)==S_OK)
    {
    if(pCont->Create(L"IIsWebServer",WNumer,&pDisp)==S_OK)
    {
    hr=pDisp->QueryInterface(IID_IADs, (void**)&pAds);
    hr=pDisp->QueryInterface(IID_IADsServiceOperations, (void**)&pSrvOp);
    pAds->Put(L"ServerSize",_variant_t(long(1)));
    pAds->Put(L"ServerComment",_variant_t(_bstr_t("masterz")));
    pAds->Put(L"ServerBindings",_variant_t(newBindings));
    pAds->SetInfo();hr=pCont->GetObject(L"IIsWebServer",(WNumer),&pDisp);
    if(pDisp->QueryInterface(IID_IADsContainer,(void**)&pCont)==S_OK)
    {
    if(pCont->Create(L"IIsWebVirtualDir",L"Root",&pVrDisp)==S_OK)
    {
    hr=pVrDisp->QueryInterface(IID_IADs, (void**)&pVrAds);
    pVrAds->Put(L"AccessRead",_variant_t(true));
    pVrAds->Put(L"AccessWrite",_variant_t(true));
    pVrAds->Put(L"AccessScript",_variant_t(true));
    pVrAds->Put(L"EnableDirBrowsing",_variant_t(true));
    pVrAds->Put(L"Path",_variant_t(pathname));
    pVrAds->Put(L"AppRoot",_variant_t(pathname));
    pVrAds->SetInfo();
    pVrAds->Release();
    pAds->Release();
    pCont->Release();
    }
    hr=pSrvOp->Start();
    hr=pSrvOp->Release();
    }
    }
    }
    return true;
    }
      

  2.   

    多谢masterz兄,虽然小弟已找到ADSI的代码,但还是非常感谢……  :)