⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.~cpp

📁 ADSI Use C Builder Example
💻 ~CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#include "iads.h"
#include "adssts.h"
#include "Adshlp.h"


TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{SpeedButton1->Down=true;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------

BOOL CreateWebServer(String ip,String domain,String DiskPath)
{
IADsContainer *pCont=NULL;
IADs* pAds=NULL;
IADs* pVrAds=NULL;
IADsServiceOperations *pSrvOp;
IDispatch *pDisp = NULL;
IDispatch *pVrDisp = NULL;
AnsiString WNumer=IntToStr(random(1000)); //取一个随机数建立站点
String newBindings=ip+":80:"+domain;
 
/* 获得WebSever */ 
if(ADsGetObject(L"IIS://localhost/w3svc",IID_IADsContainer,(void**)&pCont)==S_OK)
{   //创建站点
  if(pCont->Create(L"IIsWebServer",(wchar_t*)WideString(WNumer),&pDisp)==S_OK)
    {
       pDisp->QueryInterface(IID_IADs, (void**)&pAds);
       pDisp->QueryInterface(IID_IADsServiceOperations, (void**)&pSrvOp);
       pAds->Put(L"ServerSize",Variant(int(1)));
       pAds->Put(L"ServerComment",Variant(String("xiwei")));
       pAds->Put(L"ServerBindings",Variant(String(newBindings)));
       pAds->SetInfo();

    //创建主目录
    
   pCont->GetObject(L"IIsWebServer",(wchar_t*)WideString(WNumer),&pDisp);//得到刚才创建地网站
   if(pDisp->QueryInterface(IID_IADsContainer,(void**)&pCont)==S_OK)
   {
     if(pCont->Create(L"IIsWebVirtualDir",L"Root",&pVrDisp)==S_OK)
       {
         pVrDisp->QueryInterface(IID_IADs, (void**)&pVrAds);
         pVrAds->Put(L"AccessRead",Variant(BOOL("True")));
         pVrAds->Put(L"AccessWrite",Variant(BOOL("True")));
         pVrAds->Put(L"AccessScript",Variant(BOOL("True")));
         pVrAds->Put(L"EnableDirBrowsing",Variant(BOOL("True")));
         pVrAds->Put(L"Path",Variant(String(DiskPath)));
         pVrAds->Put(L"AppRoot",Variant(String(DiskPath)));
         pVrAds->SetInfo();
         pVrAds->Release();
         pAds->Release();
         pCont->Release();
       }
     //启动新建的WebServer
    pSrvOp->Start();
    pSrvOp->Release();
    }
   }
}

}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
CreateWebServer(Edit1->Text,"xiwei222",Edit2->Text);
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -