c++ 建立虛擬站點 (轉)

worldblog發表於2007-12-12
c++ 建立虛擬站點 (轉)[@more@]

BOOL FO_CreateVirtualSite(LPCTSTR lpszVirtualDirName,LPCTSTR lpszDiskPath,LPCTSTR lpszSitePath)
{
 IADntainer* iContainer;
 IADs* iAds;
 /* 獲得Sever */
 if(ADsGet(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.,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; //D型別
 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)
 {
 ////建立新站點目錄 
 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;
}


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-991801/,如需轉載,請註明出處,否則將追究法律責任。

相關文章