vc IIS在非默认网站下创建虚拟目录

BOOL NewSiteDlg::CreateVirtualDir(LPCTSTR lpSiteName, LPCTSTR lpszVirtualDirName, LPCTSTR lpszDiskPath)
{  
     IADsContainer *iContainer;
        IADs *iAds;
        IEnumVARIANT *pEnum;
  pEnum=GetW3SVCList();
  VARIANT var;
  ULONG lFetch;
  HRESULT hr;
  IDispatch *pDisp;
        char *sprint;
  BSTR SiteClass;
        hr=pEnum->Next(1,&var,&lFetch);
  while(hr==S_OK)
  {
       if(lFetch==1)
     {
       pDisp=V_DISPATCH(&var);
    pDisp->QueryInterface(IID_IADs,(void**)&iAds);
    iAds->get_Class(&SiteClass);
                sprint=_com_util::ConvertBSTRToString(SiteClass);
    //className=sprint;
    if((CString)sprint=="IIsWebServer")
    {
        iAds->Get(L"ServerComment",&var);
     CString tem(var.bstrVal);
     if(lpSiteName==tem)
     {
      SysFreeString(SiteClass);
                        VariantClear(&var);
                        hr=pEnum->Release();
      break;
     }
    }
   
    }
           SysFreeString(SiteClass);
           VariantClear(&var);
           hr=pEnum->Release();
           pEnum->Next(1,&var,&lFetch);
  }
        if(iAds->QueryInterface(IID_IADsContainer,(void**)&iContainer)==S_OK)
  {
            iContainer->GetObject(_bstr_t("IIsWebVirtualDir"),_bstr_t("Root"),(IDispatch**)&iAds);
      if(iAds->QueryInterface(IID_IADsContainer,(void**)&iContainer)==S_OK)
   {
    if(iContainer->Create(_bstr_t("IIsWebVirtualDir"),(_bstr_t)lpszVirtualDirName,(IDispatch**)&iAds)==S_OK)
    {
                iAds->Put(_bstr_t("AccessRead"),_variant_t(false));
       iAds->Put(_bstr_t("AccessWrite"),_variant_t(false));
       iAds->Put(_bstr_t("AccessScript"),_variant_t(false));
       iAds->Put(_bstr_t("AccessExecute"),_variant_t(false));
       iAds->Put(_bstr_t("EnableDirBrowsing"),_variant_t(false));
       iAds->Put(_bstr_t("EnableDefaultDoc"),_variant_t(false));
       iAds->Put(_bstr_t("Path"),_variant_t(lpszDiskPath));
       iAds->SetInfo();
                         iAds->Release();
       iContainer->Release();
       return true;
    }
   }
   else
   {
     iContainer->Release();
     iAds->Release();
     return false;
   }
  
  }
  iContainer->Release();     
     return false;
}

你可能感兴趣的:(Class,Path,IIS)