C ++ Builder creates a Web site using ADSI

zhaozj2021-02-11  197

C Builder creates a Web site using ADSI

The following is an article I have learned in MSDN. Summary Suitable for creating WebServer under C Builder: Use some interfaces of ADSI, pay attention to add ActiveDs.lib to the project, but also include the following headers. It is relatively simple, I hope to throw the jade.

File: // ---------------------------------------------- -----------------------------

#include #pragma HDRSTOP

#include "unit1.h"

File: // ---------------------------------------------- ----------------------------- # prgma package (smart_init) #pragma resource "* .dfm" #include "ip" #include "adssts.h" #include "adshlp.h"

TFORM1 * FORM1; __ fastcall tform1 :: tFORM1 (TComponent * Owner: TFORM (OWNER) {}

File: // Several parameters: IP: IP address string, Domain: Domain Name (www.youname.com), DiskPath: Virtual Directory Path (C: / Wwwroot) Bool CreateWeb Server (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)); // get a random Site String NewBindings = IP ": 80:" Domain; / * Get webserver * / if (ADSGETOBJECT (L "IIS: // localhost / w3svc", IID_IADSCONTAINER, (Void **) & pcont) == s_ok) { // Create a site 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")) ); // server comment, not too many use, xiwei my name Pads-> Put (L "serverbindings", variant (string (newbindings))); pads-> setInfo ();

File: // Create the primary directory PCONT-> getObject (l "iisWebserver", (Wchar_t *) WideString (WNUMER), & PDISP); // Get the website IF (PDISP-> queryinterface (IID_IADSCONTAINER, (void **) & pcont) == S_OK) {IF (PCont-> Create (L "root", & pvrdisp) == s_ok) {pvrdisp-> queryinterface (iiD_iads, (void **) & pvrads; pvrads-> put (L "AccessRead", Variant ("true"))))); pvrads-> Put (L "AccessWrite", Variant (Bool ("True")))); PVRADS-> PUT (L "AccessScript", Variant ( Bool ("true")))); pvrads-> Put (L "enabledirbrowsing", variant ("true"))); PVRADS-> PUT (L "path", variant (String (DiskPath)); PVRADS -> Put (l "approot", variant (string (diskpath))); pvrads-> setInfo (); pvrads-> release (); pads-> release (); pcont-> release ();} file: / / Start the newly built webserver psrvop-> start (); psrvop-> release ();}}}} void __fastcall tform1 :: button2click (Tobject * sender) {createWeb Server (edit1-> text, "www.cccaaa.com", Edit2-> text);} file: // ------------------------- --------------------------------------------------

The above content lacks error handling, such as IP addresses have been taken, I think technology does not use conservative, no waiting interest, have depreciated. Haha, I hope you will give it to you! My email: proton@yeah.net

转载请注明原文地址:https://www.9cbs.com/read-4507.html

New Post(0)