ADSI and its application on the Web

Source: Internet
Author: User
Tags empty iis modify new features thread window domain domain name
Web


Tags: ADSI, Component, ASP, IIS
Summary: This article briefly describes the characteristics of ADSI and illustrates how to use ADSI to develop a web-based Windows NT management program.
ADSI (Active Directory service Interface) is a Microsoft-launched application interface that allows customers to manage different directory services with the same interface, and it quickly gets a wide range of applications with powerful features and simple operations. So, what is ADSI, and how is it used?
First, understand what Active Directory is (Active Directory).
Active directory is a directory service included in future Windows2000 that extends the features of directory services in previous versions of Windows and adds some new features. The Active Directory is characterized by security, distribution, partitioning, and replication. It is designed to work well on a variety of settings, whether it is a stand-alone machine with hundreds of objects or a server group of millions of objects. The new feature of the Active Directory is that managers and end users can manipulate and manage a large amount of information.
ADSI is a series of programming interfaces that access data in a variety of storage ways, and Windows Nt4.0server,exchange,iis,site server supports this interface in Microsoft's current offerings, In NT5.0, ADSI becomes the interface of the operating system and is likely to replace the registry. With this excuse, you can access all the configuration information for the operating system.
ADSI thinks that any data is stored as an object-oriented database. With ADSI, you don't have a SQL-like query language, which is simpler for object-oriented databases than traditional databases: in a traditional database, programmers have to understand how an object is stored, and in ADSI, a programmer can access it simply by knowing the name of the object.
There are many languages that can be used to program ADSI, Visual basic,vbscript,java,c,c++ can access ADSI, and because active Server pages and VBScript are very well combined, So it's easy to write down Internet applications that access directory services. In an Internet application, you can use an. asp file to create, manipulate, and display the results of an ADSI object on a Web page on the server.
Let's look at a simple example:
Generate an ASP file that contains the following code:
<%
strMachineName = "localhost" ' Domain name
Strobjectpath = "W3SVC/1" ' Object name</p><p> ' construct object location in IIS
strpath = "iis://" & strMachineName & "/" & Strobjectpath
Set IIsObject = GetObject (strpath) ' Connect to IIS metabase
%>
Name = "<%= iisobject.name%>" <br>
Parent= "<%= iisobject.parent%>" <br>
schemalocation = "<%= iisobject.schema%>" <br>
Class = "<%= iisobject.class%>" <br>
Guid = "<%= iisobject.guid%>" <br>
ADSPath = "<%= iisobject.adspath%>" <br></P><P>
Browse with the browser, the output results are as follows: </p><p>name = "1"
Parent= "Iis://localhost/w3svc"
schemalocation = "Iis://localhost/schema/iiswebserver"
Class = "IIsWebServer"
Guid = ' {8b645280-7ba4-11cf-b03d-00aa006e0975} '
ADSPath = "IIS://LOCALHOST/W3SVC/1" </P><P> note that if the above code is to be run, the logged-on user must have administrator privileges on IIS, in order to make this application more universal, You can install the program into a build on the server. Here, for example, do a component that modifies the Windows NT user password by using ADSI programming.
1, open VB5.0 or 6.0, create a new ActiveX DLL
2, the project named Passwordchanger, the default class module named Main.
3. Change the Instancing property of class main to: 5-multiuser
4. Set the engineering thread module as: Unit thread
5. Set Microsoft Active DS Type Library (activeds.tlb)
6, Save the project, the class name is: Main.cls, the project named Passwordchanger.vbp.
7, in the code window of the class add the following code:
Option explicit</p><p> ' modify password </p><p>public Sub SetPassword (ByVal pstruser as String, _
ByVal Pstroldpassword as String, ByVal Pstrnewpassword _
As String, ByVal Pstrconfirmpassword as String) </p><p>dim Adsuser as IADsUser
Dim Strdialogtext as String</p><p>on Error GoTo Changepassworderrorhandler
' User name cannot be empty
If pstruser <> vbnullstring Then
' Password cannot be empty
If (not (Pstroldpassword = vbNullString)) and _
(Not (Pstrnewpassword = vbNullString)) Then
' Two must enter the same password twice
If (Not (Pstrnewpassword <> pstrconfirmpassword)) then</p><p> ' Set ADSI provider to WindowsNT
' (Domain-primary)
Set Adsuser = GetObject ("winnt://domain/" & Pstruser & ", user") </P><P> ' Invoke ADSI ChangePassword method
Adsuser.changepassword Pstroldpassword, Pstrnewpassword
' Generate HTML dialog box on browser side
Strdialogtext = "" Successfully modified User "& Pstruser & _
"." "
Call Createalertmarkup (strdialogtext) </P><P>Else</P><P> ' Generate HTML dialog box on browser side
Strdialogtext = "" "New/confirm passwords are different." "
Call Createalertmarkup (strdialogtext) </p><p>end if</p><p>else</p><p> ' generated at the browser end HTML dialog box
Strdialogtext = "" "A value for old/new passwords is required." "" "" ""
Call Createalertmarkup (strdialogtext) </p><p>end if</p><p>end If</P><P>Set Adsuser = Nothing</p><p>exit sub</p><p> ' **********</p><p> Changepassworderrorhandler:</p><p> '
' Generate prompt on browser side error ' dialog box
The password for strdialogtext = "" "User & Pstruser &" cannot be modified. \ n "
Strdialogtext = Strdialogtext & "1. New password cannot be "& _
"Same as previous password \ n"
Strdialogtext = Strdialogtext & "2. Password must be "& _
"8-14 letters long. \ n"
Strdialogtext = Strdialogtext & "3. Password must contain at least "& _
"3 letters in the following cases: \ n"
Strdialogtext = Strdialogtext & "-English capital letter (A-Z) \ n"
Strdialogtext = Strdialogtext & "-English lowercase mu (A-Z) \ n"
Strdialogtext = strdialogtext & "-Arabic numerals (0-9) \ n"
Strdialogtext = Strdialogtext & "-Other characters" & _
"(for example, punctuation) \ n"
Strdialogtext = Strdialogtext & "4. Password cannot contain your username "& _
"or any part of your name," "
Call Createalertmarkup (strdialogtext) </p><p>end sub</p><p> ' Generate JavaScript warning dialog box
Private Sub createalertmarkup (pstrdialogtext as String) </p><p>dim Strscriptinglanguage as string</p ><p>strscriptinglanguage = "" JavaScript "" "</p><p>objresponse.write vbCrLf
Objresponse.write ("<script language=" & Strscriptinglanguage & ">") & vbCrLf
Objresponse.write ("<!--") & VbCrLf
Objresponse.write ("{") & VbCrLf
Objresponse.write VbTab & ("Window.alert (" & Pstrdialogtext &); ") & VbCrLf
Objresponse.write ("}") & VbCrLf
Objresponse.write ("-->") & VbCrLf
Objresponse.write ("</SCRIPT>") & Vbcrlf</p><p>end Sub
8, compile this code, generate PasswordChanger.dll.
9. Copy the resulting PasswordChanger.dll file to the Winnt\System32 directory.
10. Execute the following command in the DOS prompt window:
The regsvr32 passwordchanger.dll</p><p> system will pop up a dialog box to tell you that the registration component is successful. Below, you need to write an ASP file to invoke this component.
<%</P><P> ' Declare variables
Dim objreference
Dim struser
Dim Stroldpassword
Dim Strnewpassword
Dim strconfirmnewpassword </P><P> ' obtain form values
struser = Request.Form ("Txtuser")
Stroldpassword = Request.Form ("Txtoldpassword")
Strnewpassword = Request.Form ("Txtnewpassword")
Strconfirmnewpassword = Request.Form ("Txtconfirmnewpassword")
If struser<> "" Then</p><p> ' Create object
Set objreference = Server.CreateObject ("Passwordchanger.main") </P><P> ' Change the password
Call Objreference.setpassword (Struser,stroldpassword,strnewpassword,strconfirmnewpassword) </P><P> ' Release object reference
Set objreference = Nothing
End If
%>
<title> Modify NT user password </title>
<table width=325 border= "0" >
<tr>
&LT;TD colspan=2><b>
<font size=+1 face=arial color=black>
User:
</font>
</b>
</td>
<td>
<input type=text size=20 name= "Txtuser" ></td>
</tr>
<tr>
&LT;TD colspan=2><b>
<font size=+1 Color=black face=arial>
Password:
</font>
</b>
</td>
<td><font>
<input type= "Password" name= "Txtoldpassword" >
</font></td>
</tr>
<tr>
&LT;TD colspan=2>
<b>
<font size=+1 Color=black face=arial>
New Password:
</font>
</b>
</td>
<td>
<font>
<input type= "Password" name= "Txtnewpassword" >
</font>
</td>
</tr>
<tr>
&LT;TD colspan=2><b>
<font size=+1 Color=black face=arial>
Confirm Password:
</font></b></td>
<td>
<input type= "Password" name= "Txtconfirmnewpassword" >
</font></td>
</tr>
<tr>
&LT;TD colspan=3></td>
</tr>
<tr>
&LT;TD colspan=3>
<div align=center>
<font Color=black face=arial>
<input Id=txtchangepassword Name=txtchangepassword
Style= "font-family:; height:24px; Width:149px "Type=submit value=" Change Password ">
</div>
</font>
</td>
</tr>
</table>
</form>
</body>
Name this file changepwd.asp, run in the browser, enter data test, how, the user's password has been modified? </P><P> through the above examples, ADSI does have a very powerful function, and the operation is very simple, combined with ASP and VB, will certainly be able to develop more powerful Internet applications.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.