如何通过ASP管理NT帐号
程序员文章站
2023-11-29 18:20:28
'============================================================= ' &nbs...
'=============================================================
' 感谢您使用asp001工作室开发的实用函数程序
' http://www.asp001.net
'============================================================= 'asp001工作室为您提供订制程序开发、企业互联网拓展服务
'qq:1974229
'e-mail:shenyangchuqi@tom.com
'更多程序下载请到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
' 感谢您使用asp001工作室开发的实用函数程序
' http://www.asp001.net
'============================================================= 'asp001工作室为您提供订制程序开发、企业互联网拓展服务
'qq:1974229
'e-mail:shenyangchuqi@tom.com
'更多程序下载请到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
上一篇: 搜狗输入法三则小技巧使用更方便