'=============================================================
' 感謝您使用ASP001工作室開發的實用函數程序
' HTTP://WWW.ASP001.NET
'============================================================= 'ASP001工作室為您提供訂制程序開發、企業互聯網拓展服務
'QQ:1974229
'E-Mail:
[email protected] '更多程序下載請到HTTP://WWW.ASP001.NET
'=============================================================
'函數介紹:通過ASP管理NT帳號
'本函數使用ADSI,需要Administrators組用戶權限
'程序開發:ASP001工作室 ChuQi
'=============================================================
'填加用戶
'函數用法:AddUser(Computer,UserName,PassWord,FullName,Info)
'參數:計算機名,帳號名稱,帳號密碼,帳號全名,帳號說明
'例:AddUser "127.0.0.1","Test","Test","測試管理員帳號","本帳號通過ASP填加"
'修改指定用戶基本信息
'函數用法:EditUser(Computer,UserName,OldPassWord,PassWord,FullName,Info)
'參數:計算機名,帳號名稱,帳號密碼,帳號全名,帳號說明
'例:EditUser "127.0.0.1","Test","Test2","測試管理員帳號修改","本帳號通過ASP修改過"
'刪除指定用戶
'函數用法:DelUser(Computer,UserName)
'參數:計算機名,用戶名'
'例:DelUser "127.0.0.1","Test"
=============================================================
Function AddUser(Computer,UserName,PassWord,FullName,Info)
'執行創建帳號命令
Set ComputerObj = GetObject("WinNT://"&Computer)
Set NewUser = ComputerObj.Create( "User" , UserName )
NewUser.SetInfo
'進行帳號設置
NewUser.SetPassword ( PassWord ) '帳號密碼
NewUser.FullName = FullName '帳號全名
NewUser.Description = Info '帳號說明
NewUser.UserFlags = &H10000 '&H20000(使用者下次登入時須變更密碼) &H0040(使用者不得變更密碼) &H10000(密碼永久正確) &H0002(帳戶暫時停用)
NewUser.SetInfo
response.write "帳號"&UserName&"創建成功!"
Set ComputerObj=nothing
End Function
Function EditUser(Computer,UserName,OldPassWord,PassWord,FullName,Info)
'讀取用戶信息
Set ChangeUserObj = GetObject("WinNT://"&Computer&"/"&UserName&",User")
'修改帳號密碼
if PassWord<>"" then
ChangeUserObj.SetPassword PassWord
response.write "帳號密碼修改成功!<br>"
end if
'修改帳號全名
if FullName<>"" then
UserFullName = ChangeUserObj.get("FullName")
ChangeUserObj.FullName = FullName
ChangeUserObj.SetInfo
response.write "帳號全名修改成功!<br>"
end if
'修改帳號說明
if Info<>"" then
UserFullName = ChangeUserObj.get("Description")
ChangeUserObj.Description = Info
ChangeUserObj.SetInfo
response.write "帳號說明修改成功!<br>"
end if
Set ChangeUserObj=nothing
End Function
Function DelUser(Computer,UserName)
Set DelUserObj = GetObject("WinNT://"&Computer&"/"&UserName)
If Err = &H800401E4 Then
Response.Write "用戶"&UserName&"不存在"
Response.End
End If
Set DelObj = GetObject(DelUserObj.Parent)
DelObj.Delete "User", DelUserObj.Name
Set DelUserObj = Nothing
Set DelObj = Nothing
Response.Write "刪除成功"
End Function