Create
Some time ago to write a program, but not perfect, can not determine whether there is the user, now complement the lookup function.
Code deficiencies, hope feel free!
The complete code is as follows:
<%@ language=vbscript codepage= "936"%>
<% Option Explicit%>
<HTML>
<HEAD>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<meta name= "generator" content= "Microsoft Visual Studio 7.0" >
</HEAD>
<BODY>
<%
' Program Purpose: Create Exchange 2000 Mailbox users
' Program implementation: first in AD (Active Directory: Active Directory) to find if there is a
' User, if there is a hint that the name already exists, does not create the user,
' and create a mailbox for that user.
' Programming: Skyword, skyword@21cn.com
' Program Date: 2001-06-27
' The problem to be noted: in the use of programs, you should pay attention to the differences in LDAP. and the program needs to run more than
' higher than the main running permissions (I use is administrator rights, hehe more unsafe,
' Everyone in the actual use to pay attention to, or be stolen from the account do not blame me.
' I'm not very good at setting it up, I need to set it up in IIS (previously because I didn't understand
', took a lot of detours:)
' There is also a scheme to find the user can combine the database lookup, I think we
' will be more familiar, just remember in the initial data, to the computer
' Some accounts have to be logged into the database, or you can not be prepared to decide whether to use
' Because ad only judges whether there is a user, regardless of where it is, this
' Dot everybody should notice.
' The program is used in some knowledge points are annotated, I hope to help
The other thing to note is that the account name must not be less than 2 digits, and can not use Chinese
Name.
Dim objuser
Dim Objcontainer
Dim Objmailbox
Dim objmail
Dim Recipname, Recip
Dim ServerName, domainname, EmailName, FirstName, LastName, password
' Determine if the user exists
Dim strquery, objconn, objRS, strresult
' Query statement: syntax: What to look for, that is, find the base (<LDAP://DC=program,DC=org>);
' Find out where in the directory (& (Objectcategory=person) (samaccountname= user
' Name ') (user is? The user who found the object's properties (Samaccount,adspath) (user name,
' LDAP address '; The scope of the lookup (subtree: Find the entire subtree below the base of the search). Example
' is the following sentence.
' For details, refer to ASP3 advanced programming P644, Machinery Industry publishing house (as if the essence of the region
' There's an electronic document for this book, this book is really good, it's worth buying.
strquery = "<LDAP://DC=program,DC=org>;(& (Objectcategory=person)" & _
"(samaccountname=" & Request.Form ("txtUserName") &)); "& _
"Samaccountname,adspath;subtree"
' Open ADSI
Set objconn = Server.CreateObject ("ADODB. Connection ")
Objconn.provider = "Adsdsoobject"
' The following sentence is opened with a legitimate user, otherwise the result of the search is incorrect, in this case, using the Administrator account
objConn.Open "Active Directory Provider", "Cn=administrator, Cn=users, Dc=program, dc=org", "Skyword"
' Find out if a user exists or not, create a user
Set objRS = Server.CreateObject ("ADODB. Recordset ")
Objrs.open strquery, objconn
If not objrs.eof Then
strresult = False
Response.Write "User already exists"
Else
' Create user
strresult = True
End If
Objrs.close
Set objRS = Nothing
Objconn.close
Set objconn = Nothing
If strresult = True Then
' Create the user's code
' Servername,domainname is required for the LDAP information required by ADSI.
ServerName = "skyword.program.org"
DomainName = "Dc=program,dc=org"
EmailName = Request.Form ("txtUserName")
Password = Request.Form ("Txtpassword")
Recip = "cn=" & EmailName
' The following if statement is of little value. :)
If Request.Form ("Txttruename") <> "" Then
LastName = "Sky"
FirstName = "Word"
Else
LastName = "Last"
FirstName = "Name"
End If
' Open Object
Set Objcontainer = GetObject ("ldap://" & ServerName & "/ou=china.org," & DomainName)
' Create an Account
Set objuser = objcontainer.create ("User", Recip)
objUser.Put "sAMAccountName", EmailName ' account
objUser.Put "SN", LastName
objUser.Put "givenname", FirstName
objUser.Put "DisplayName", EmailName ' & ' @hina. org "' shows the name
objUser.Put "Mail", EmailName & "@China. org"
objUser.Put "userPrincipalName", EmailName & "@China. org" ' User login account
Objuser.setinfo ' writes into the ad
Objuser.setpassword Password ' user password
objuser.accountdisabled = False ' account number in effect
Objuser.setinfo ' write into AD, must, why I don't know
' Create a mailbox
Set Objmailbox = objuser
' The LDAP below is checked out, the installation is different, and LDAP will vary.
Objmailbox.createmailbox "ldap://skyword.program.org/" & _
"Cn=mailbox Store (Skyword), Cn=first Storage Group," & _
"Cn=informationstore,cn=skyword,cn=servers," & _
"Cn=first Administrative group,cn=administrative Groups," & _
"Cn=ecitye,cn=microsoft exchange,cn=services," & _
"Cn=configuration,dc=program,dc=org"
Objuser.setinfo
Set Objcontainer = Nothing
Set objuser = Nothing
Set Objmailbox = Nothing
' Here is a simple error-handling.
If Err <> 0 Then
Response.Write "Create User failed!" Please try again <br> "
Response.Write ' <input type= ' button ' value= ' Retry ' > '
Response.Write "<input type= ' button ' value= ' Return ' >"
Else
' The following is a simple test
Set objmail = Server.CreateObject ("CDONTS. NewMail ")
Objmail.send "Admins@china.org", EmailName & "@china. org", "Welcome", "Welcome use china.org Mail"
Set objmail = Nothing
Response.Write EmailName & User has been successfully created!!!! "&" <br> three seconds to guide the login page! "
Response.AddHeader "Refresh", "3;url=http://mail.china.org"
End If
End If
%>
</BODY>
</HTML>