c++ 建立虚拟站点

类别:VC语言 点击:0 评论:0 推荐:

BOOL FO_CreateVirtualSite(LPCTSTR lpszVirtualDirName,LPCTSTR lpszDiskPath,LPCTSTR lpszSitePath)
{
 IADsContainer* iContainer;
 IADs* iAds;
 /* 获得WebSever */
 if(ADsGetObject(L"IIS://localhost/",IID_IADsContainer,(void**)&iContainer)==S_OK)
 {
 // LONG g=0;
 // iContainer->get__NewEnum
// iContainer->get_Count(&g);

//此处是可以通过枚举的方式获得。此处没有具体实现所以本例只能建立一个站点。
  LONG i =20;
  char c[10];
  ZeroMemory((PVOID)c,10);
  itoa(i,c,10);
  //建立虚拟站点
  if(iContainer->Create(L"IIsWebServer", _bstr_t(c),(IDispatch**)&iAds)==S_OK)
  {
   //设置虚拟站点的属性
   VARIANT var;
   VariantInit(&var);
 
   V_BSTR(&var) = SysAllocString(_bstr_t(lpszDiskPath));
   V_VT(&var) = VT_BSTR;
   iAds->Put(L"ServerComment", var); //设置站点名
   VariantClear(&var);
   
   V_BSTR(&var) = SysAllocString(L":9999:");
   V_VT(&var) = VT_BSTR;
   iAds->Put(L"Serverbindings", var); //  //设置站点端口号
   VariantClear(&var);
   
   V_BSTR(&var) = SysAllocString(L"default.asp,index.asp,default.htm,index.htm");
   V_VT(&var) = VT_BSTR;
   iAds->Put(L"DefaultDoc", var);//设置默认启动文件
   VariantClear(&var);
   
   V_BSTR(&var) = SysAllocString(L"True");
   V_VT(&var) = VT_BOOL;
   
   iAds->Put(L"AccessScript", var); // 设置读取权限
   iAds->Put(L"AccessRead",var);  
   iAds->Put(L"AccessWrite",var);
  
   VariantClear(&var);
  
   V_UI4(&var) = 1;  //DWORD类型
   V_VT(&var) = VT_UI4;
   iAds->Put(L"ServerAutoStart", var);//
   VariantClear(&var);
   
   iAds->SetInfo();
   
   if(ADsGetObject(L"IIS://localhost/w3svc",IID_IADsContainer,(void**)&iContainer)==S_OK)
   {
    if (iContainer->GetObject(L"IIsWebServer", _bstr_t(c),(IDispatch**)&iAds)==S_OK)
    {
     if(iAds->QueryInterface(IID_IADsContainer,(void**)&iContainer)==S_OK)
     {
      ////创建新站点root目录 
      if(iContainer->Create(L"IIsWebVirtualDir", L"Root",(IDispatch**)&iAds) == S_OK)
      {
       //设置新站点的根目录
       V_BSTR(&var) = SysAllocString(_bstr_t(lpszSitePath));
       V_VT(&var) = VT_BSTR;
       iAds->Put(L"AppCreate", var);
       iAds->Put(L"Path",var);
      }
     }
    }
   }  
   iAds->SetInfo();
   //打扫卫生
   iAds->Release();
   iContainer->Release();
   iContainer->Release();
   return TRUE;
  }
  else
  {
   //同上,不过没利索
   iContainer->Release();
   return FALSE;
  }
  //同同上
  iContainer->Release();
 }
 return FALSE;
}

本文地址:http://com.8s8s.com/it/it2285.htm