Manage Internet Information Server via ADSI

zhaozj2021-02-11  218

Manage Internet Information Server via ADSI

Deng Zhenbo

Active directory is integrated in Windows2000 directory services. Active Directory Similar to the database. Users can add or clear the project to the active directory, and in most cases, the items in the active directory are lasting. Although the active directory is similar to a database, the active directory does not use a large number of free information, nor is not used to regularly update frequently changed data. ADSI provides a single set of directory service interfaces for managing network resources. The management task on IIS can be performed using the ADSI to easily use the client's code. The main object used for these tasks is ISAO (IIS Administration Objects, IIS Administration object), which has a COM object with an interface that adapts to ADSI. These objects help customize the application's development, these applications have the ability to create and configure virtual directories, websites, and FTP sites. You can use a variety of development tools and development languages ​​to implement management, whether ASP, C , Visual Basic, and many other development environments that support COM. This article tries to describe an example of a management web site using VB and VC. Through this example, you can understand some of the basic frames and steps of the ADSI program. Each ADSI has basic properties is Adspath, Class, GUID, Name, Parent, Schema. The following description is as follows:

Property Description ADSPATH contains a path that uniquely identifies this object, uses to take this object Class Identifier Object Program class in GetObject, the name of the object, contains an optional unique identifier of the object of this plan, in the underlying namespace Name Parent contains AdspathChema of the parent container object Description this class object's AdSpath

Below to use the ADSI Management IIS Web Server as an example, the use of the active directory is described. Using ADSI in Visual Basic, you must add a reference to Active DS Type Library (ActiveDs.TLB). Use ADSI in Visual C , need #include activeds.h, connect to ActiveDs.lib and Adsiid.lib library files, and use the Unicode string.

The following example is an example of creating a Web site using VB. Multi-site can only create, NT workstations or Win2K Professional on NT Server, and does not support creation multi-site.

'====================================================== Wwwtcpport To the new site TCP port 'wwwfilespath new site's main directory path' computername needs to establish a virtual site on that machine, this machine can use localhost '================== ========= Function CreateWebSit (ByVal WWWSiteName As String, _ByVal WWWTCPPort As String, _ByVal WWWFilesPath As String, _ByVal ComputerName As String) As BooleanCreateWebSit = TrueDim TCPPort () As Variant 'establish active desktop' (IADS) objects .

First of all to lead 'with Active DS' Type 'library components Dim WWWServer As IADs, WWWService As IADs, WWWVdir, WWWVdirRes As IADsDim I As IntegerDim HandleSameCase As Boolean' in VB 'prject' menu 'references' acquired in the W3SVC service Set WWWService = GetObject ( "IIS: //" & ComputerName & "/ W3SVC") I = 1HandleSameCase = TrueOn Error GoTo ErrWouldDo 'find each WEB site For each wWWServer in WWWServiceSet wWWServer = NothingSet wWWServer = GetObject ( "IIS in IIS : // "& i) Debug.print wwwserver.servercomment 'If there is already a site to be added during the installation, you must first remove the clean IF ucase (wwwserver.servercomment) = ucase (Wwwsitename) Thenwwservice.delete "IisWeb Server", I 'Remove EXIT Forend ifredim tcpport (1) Tcpport (0) = "" Tcpport = wwwserver.serverbindings "If the port already has, I must first delete if tcpport (0) = ":" & WWWTCPPort & ":" ThenWWWService.Delete "IISWebServer", I 'delete ElseI = I 1End IfNextHandleSameCase = FalseCreateSite:' MsgBox ISet wWWServer = WWWService.Create ( "IISWebServer", I) 'create a new site WWWServer.ServerComment = WWWSITENAME 'Setting Site Name WWWServer.ServerBindings = ":" & Wwwtcpport & ":" Settings Slogan WWWServer.DefaultDoc = "default.asp, index.asp, default.htm, index.htm" 'set the default startup file WWWServer.AccessScript = True' to set permissions WWWServer.AccessRead = TrueWWWServer.SetInfo 'home directory to create settings Set WWWServer = GetObject ("IIS: //" & i) set wwwvdir = wwwserver.create ("IisWebVirtualDir", "root") wwwvdir.path = The actual disk path of the home directory wwwvdir.setinfowwwvdir. AppCreate TruewWServer.Start '

Start a new site Set WWWVdirRes = WWWVdir.Create ( "IISWebVirtualDir", "Resource") 'create a virtual directory WWWVdirRes.Path = WWWFilesPath "/Resource"WWWVdirRes.AccessRead = TrueWWWVdirRes.AccessWrite = TrueWWWVdirRes.SetInfo' following the custom IIS Web Server error message, wait 404 error When you specify the 404.htm page under the home directory of the website to display wwwserver.httperrors = "404, 0, file," wwwfilespath "/404.htm "wwswserver.setInfocreateWouldDo: 'MsgBox Err.DescriptionIf (HandleSameCase = True) ThenGoTo CreateSiteElseMsgBox Err.DescriptionCreateWebSit = FalseExit FunctionEnd IfEnd Function for example, to use port 9000 on the machine to create a name (description) of MySite site and the C: / C: / MyWebRoot provided Set to the home directory, you can call: CreateWebsit "Mysite", "9000", "C: / MyWebroot", "Localhost"

Examples of this VB above illustrate the basic steps and properties of the ADSI in VB (the data type of the attribute including String, List, Boolean settings). For more IIS properties, please refer to the MSDN ADSI topic (recommended to use the new version of MSDN, in fact, my no new - 2000 OCT version)

An example of using ADSI in one of the following VCs, which is different from VB, which is the virtual directory that uses VC in the default Web site.

//// CREATEVIRTUALDIRECTION Parameter Description // LPSZVIRTUALDIRNAME Requires Directory Name // LPSZDiskPath Need to create a local disk directory of a virtual directory ///

BOOL CreateVirtualDirection (LPCTSTR lpszVirtualDirName, LPCTSTR lpszDiskPath) {IADsContainer * iContainer; IADs * iAds; / * get WebSever * / if (ADsGetObject (L "IIS: // localhost / w3svc", IID_IADsContainer, (void **) & iContainer) == S_ok) {// Wait until the default site icontainer-> getObject (_BSTR_T ("IisWebserver"), _BSTR_T ("1"), (iDispatch **) & Iads); if (IADS-> Queryinterface (IID_IADSCONTAINER, (Void **) & icontainer ) == S_OK) {// Get the root of the default site icintainer-> getObject (_BSTR_T ("IisWebVirtualDir"), _ bstr_t ("root"), (iDispatch **) & Iads); // Get access virtual directory IF (IADS) -> queryinterface (IID_IADSCONTAINER, (Void **) & icontainer) == S_OK) {// Delete the virtual directory icontainer-> delete (_BSTR_T ("IisWebVirtualDir"), _bstr_t (lpszvirtualDirName); // Establish a virtual directory IF ( icontainer-> Create (_BSTR_T ("IisWebVirtualDir"), _BSTR_T (LPSZVIRTUALDIRNAME), (iDispatch **) & IADS) == S_OK) {// Setting the attribute IADS-> PUT (_BSTR_T ("AccessRead"), _ variant_t ( "True")); // Note that IADS-> PUT (_BSTR_T ("ZRUE")); Iads-> Put (_bstr_t ("path"), _ variant_t ("path"), _ variant_t ("path"), _ variant_t ("path"), _ variant_t ("path") LpszdiskPath); Iads-> setInfo (); Iads-> Release (); IADS-> Release (); icontaine R-> Release (); icontainer-> Release (); return true;} else {iads-> release (); Iads-> Release (); icontainer-> release (); icntainer-> release (); return false }} else {Iads-> Release (); icontainer-> release ();}} else {}}} else {}-> release ();} icintainer-> release ();} returnaf false;} // Using VC need to initialize COM Environment, don't forget the call of the AFXoleinit () function in the app class. Examples of the above two VBs, VCs illustrate the basic method of use of ADSI. For more content, please refer to the MSDN description.

More articles, please see http://seesi.51.net

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

New Post(0)