何梦宁的个人主页
当前分类:所有文章 >
· [转] 批量生成windows 2000域用户2008-5-27 16:58:49

批量生成windows 2000域用户 luyear - delphi2007.net
http://www.delphi2007.net/delphiblog/html/delphi_20035810460031.html
自己还没有机会测试,仅供参考
1. 输入如下asp代码,命名为createbatch.asp, 把它的NTFS权限设成只有administrators可以访问,这很重要,不然会有意外的错误。 
<% @Language=VBScript %> 
<% Option Explicit %> 
<% On error resume next 
Dim MdfyObject 
Dim RootDSE 
Dim Container 
Dim RelativePathToObject 
Dim ObjectClass 
Dim ObjectName 
Dim NewObject 
Dim objectRelativeName 
Dim MandatoryProperty1_Name 
Dim MandatoryProperty1_Value 
Dim MandatoryProperty2_Name 
Dim MandatoryProperty2_Value 
Dim MandatoryProperty3_Name 
Dim MandatoryProperty3_Value 
Dim MandatoryProperty4_Name 
Dim MandatoryProperty4_Value 
Dim MandatoryProperty5_Name 
Dim MandatoryProperty5_Value 
Dim MandatoryProperty6_Name 
Dim MandatoryProperty6_Value 
Dim MandatoryProperty7_Name 
Dim MandatoryProperty7_Value 
Dim MandatoryProperty8_Name 
Dim MandatoryProperty8_Value 
Dim MandatoryProperty9_Name 
Dim MandatoryProperty9_Value
Dim Password 
Dim objConn 
Set objConn=Server.CreateObject("ADODB.Connection") 
objConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("test.mdb") 
Dim strSQL 
strSQL = "SELECT * FROM test" 
Dim objRS 
Set objRS = Server.CreateObject ("ADODB.Recordset") 
objRS.Open strSQL, objConn 
' Response.Write ("<b>Creating accounts...</b><br>") 
Do While Not objRS.EOF 
' Define more mandatory properties as needed 
RelativePathToObject = "ou=" & objRS("Diploma") & "," 
ObjectClass = "user" 
ObjectRelativeName = "cn=" & objRS("FullName") 
MandatoryProperty1_Value = objRS("ID") 
MandatoryProperty1_Name = "sAMAccountName" 
MandatoryProperty2_Value = objRS("ID") 
MandatoryProperty2_Name = "UserPrincipalName" 
MandatoryProperty3_Value = 16 
MandatoryProperty3_Name = "UserAccountControl" 
MandatoryProperty4_Value = objRS("Class") 
If isnull(MandatoryProperty4_Value) or MandatoryProperty4_Value = "" then 
MandatoryProperty4_Value=" " 
end if 
MandatoryProperty4_Name = "description" 
MandatoryProperty5_Value = objRS("Class") 
If isnull(MandatoryProperty5_Value) or MandatoryProperty5_Value = "" then 
MandatoryProperty5_Value=" " 
end if 
MandatoryProperty5_Name = "department" 
MandatoryProperty6_Value = objRS("FullName") 
If isnull(MandatoryProperty6_Value) or MandatoryProperty6_Value = "" then 
MandatoryProperty6_Value=" " 
end 
if MandatoryProperty6_Name = "GivenName" 
MandatoryProperty7_Value = objRS("Mail")
If isnull(MandatoryProperty7_Value) or MandatoryProperty7_Value = "" then 
MandatoryProperty7_Value=" " 
end if 
MandatoryProperty7_Name = "mail" 
MandatoryProperty8_Value = objRS("FullName") 
If isnull(MandatoryProperty8_Value) or MandatoryProperty8_Value = "" then 
MandatoryProperty8_Value=" " 
end if 
MandatoryProperty8_Name = "DisplayName" 
MandatoryProperty9_Value = "0" 
MandatoryProperty9_Name = "PwdLastSet" 
Password= objRS("Password") 
' If you dimensioned additional mandatory properties, assign them here 
Set RootDSE = GetObject(LDAP://RootDSE) 
Set Container = GetObject("LDAP://" & RelativePathToObject & RootDSE.Get("defaultNamingContext")) 
Set NewObject = Container.Create(ObjectClass , ObjectRelativeName) 
NewObject.Put MandatoryProperty1_Name, MandatoryProperty1_Value 
NewObject.Put MandatoryProperty2_Name, MandatoryProperty2_Value 
NewObject.Put MandatoryProperty3_Name, MandatoryProperty3_Value 
NewObject.Put MandatoryProperty4_Name, MandatoryProperty4_Value 
NewObject.Put MandatoryProperty5_Name, MandatoryProperty5_Value 
NewObject.Put MandatoryProperty6_Name, MandatoryProperty6_Value 
NewObject.Put MandatoryProperty7_Name, MandatoryProperty7_Value 
NewObject.Put MandatoryProperty8_Name, MandatoryProperty8_Value 
' Assign additional mandatory properties to the object here 
NewObject.SetInfo 
If len(password)>0 then 
NewObject.setpassword(password) 
End if 
'set NewObject = Nothing 
'Set RootDSE = GetObject(LDAP://RootDSE) 
'Set Container = GetObject("LDAP://" & RelativePathToObject & RootDSE.Get("defaultNamingContext")) 
Set MdfyObject = Container.getObject(ObjectClass , ObjectRelativeName) 
MdfyObject.Put MandatoryProperty9_Name, MandatoryProperty9_Value 
MdfyObject.SetInfo 
set MdfyObject = Nothing 
set NewObject = Nothing 
objRS.MoveNext Loop 
objRS.close set 
objRS = Nothing 
objconn.close 
set objconn = Nothing 
response.write ("Creating of Accounts Successfully!") 
'response.write objectClass & "<br>" %> </P><P><BR>

2. 创建一个Access数据库文件,命名为test.mdb, 在其中创建一个表,命名为test, 表的内容如附图。这个数据库的信息当然是从现成
的其它格式的文件传化来的,不然我这种方法的便利就打个折扣了。表中的ID是用户帐号,FullName是用户的全名,Diploma代表专业(将
会是OU),Class代表班级(将会是Description和Department),Mail代表用户的Email, Password代表要赋给用户的初始密码。我的
程序设置成用户第一次登陆时被提示必须修改密码。你们可以根据实际情况做相应的修改,但是程序也要跟着变。 
3.在AD中创建以Diploma中所出现的字段命名的OU, 在这里是:CST,ChE, FSN. 
4.把createbatch.asp, test.mdb拷贝到同一个目录下(记住修改createbatch.asp的NTFS属性),并web Sharing之, 然后访问它。 
5.大功告成!

转载到我的博客>>>      阅读( 2587 ) ┆ 收藏

关于六度  |  会员服务  |  联系我们  |  招贤纳士  |  广告中心  |  商务合作  |  服务条款  |  友情链接  |  网站地图
2005-2007 六度网 版权所有 粤ICP备06059169号