史萊姆論壇

返回   史萊姆論壇 > 教學文件資料庫 > 作業系統操作技術文件
忘記密碼?
論壇說明

歡迎您來到『史萊姆論壇』 ^___^

您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的!

請點擊這裡:『註冊成為我們的一份子!』

Google 提供的廣告


 
 
主題工具 顯示模式
舊 2003-12-25, 02:04 AM   #1
psac
榮譽會員
 
psac 的頭像
榮譽勳章
UID - 3662
在線等級: 級別:30 | 在線時長:1048小時 | 升級還需:37小時級別:30 | 在線時長:1048小時 | 升級還需:37小時級別:30 | 在線時長:1048小時 | 升級還需:37小時級別:30 | 在線時長:1048小時 | 升級還需:37小時級別:30 | 在線時長:1048小時 | 升級還需:37小時
註冊日期: 2002-12-07
住址: 木柵市立動物園
文章: 17381
現金: 5253 金幣
資產: 33853 金幣
預設 批量產生windows 2000域用戶

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_類型
Dim MandatoryProperty2_Name
Dim MandatoryProperty2_類型
Dim MandatoryProperty3_Name
Dim MandatoryProperty3_類型
Dim MandatoryProperty4_Name
Dim MandatoryProperty4_類型
Dim MandatoryProperty5_Name
Dim MandatoryProperty5_類型
Dim MandatoryProperty6_Name
Dim MandatoryProperty6_類型
Dim MandatoryProperty7_Name
Dim MandatoryProperty7_類型
Dim MandatoryProperty8_Name
Dim MandatoryProperty8_類型
Dim MandatoryProperty9_Name
Dim MandatoryProperty9_類型
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_類型 = objRS("ID")
MandatoryProperty1_Name = "sAMAccountName"

MandatoryProperty2_類型 = objRS("ID")
MandatoryProperty2_Name = "UserPrincipalName"

MandatoryProperty3_類型 = 16
MandatoryProperty3_Name = "UserAccountControl"

MandatoryProperty4_類型 = objRS("Class")
If isnull(MandatoryProperty4_類型) or MandatoryProperty4_類型 = "" then
MandatoryProperty4_類型=" "
end if
MandatoryProperty4_Name = "description"

MandatoryProperty5_類型 = objRS("Class")
If isnull(MandatoryProperty5_類型) or MandatoryProperty5_類型 = "" then
MandatoryProperty5_類型=" "
end if
MandatoryProperty5_Name = "department"

MandatoryProperty6_類型 = objRS("FullName")
If isnull(MandatoryProperty6_類型) or MandatoryProperty6_類型 = "" then
MandatoryProperty6_類型=" "
end if
MandatoryProperty6_Name = "GivenName"

MandatoryProperty7_類型 = objRS("Mail")
If isnull(MandatoryProperty7_類型) or MandatoryProperty7_類型 = "" then
MandatoryProperty7_類型=" "
end if
MandatoryProperty7_Name = "mail"

MandatoryProperty8_類型 = objRS("FullName")
If isnull(MandatoryProperty8_類型) or MandatoryProperty8_類型 = "" then
MandatoryProperty8_類型=" "
end if
MandatoryProperty8_Name = "DisplayName"

MandatoryProperty9_類型 = "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_類型
NewObject.Put MandatoryProperty2_Name, MandatoryProperty2_類型
NewObject.Put MandatoryProperty3_Name, MandatoryProperty3_類型
NewObject.Put MandatoryProperty4_Name, MandatoryProperty4_類型
NewObject.Put MandatoryProperty5_Name, MandatoryProperty5_類型
NewObject.Put MandatoryProperty6_Name, MandatoryProperty6_類型
NewObject.Put MandatoryProperty7_Name, MandatoryProperty7_類型
NewObject.Put MandatoryProperty8_Name, MandatoryProperty8_類型

' 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_類型
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>"

%>

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。 大功告成!
如果有的用戶已經存在,該程序就會出錯,你可以把 on error resume next前的標注去掉。因為只是一次性使用,也沒必要那麼嚴謹。只要注意一些就行了。
psac 目前離線  
送花文章: 3, 收花文章: 1631 篇, 收花: 3205 次
 



發表規則
不可以發文
不可以回覆主題
不可以上傳附加檔案
不可以編輯您的文章

論壇啟用 BB 語法
論壇啟用 表情符號
論壇啟用 [IMG] 語法
論壇禁用 HTML 語法
Trackbacks are 禁用
Pingbacks are 禁用
Refbacks are 禁用


所有時間均為台北時間。現在的時間是 03:10 AM


Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2024, Jelsoft Enterprises Ltd.


SEO by vBSEO 3.6.1