大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> ASP专区 -> Learning ADSI - Part I: Adding Users To W2K

Learning ADSI - Part I: Adding Users To W2K

时间: 2021-07-31 作者:daque

Learning ADSI - Part I: Adding Users To W2Kby remie bolte print this article email this article to a colleague introductionas the desire and need for the internet grew, microsoft created new products and modified its old ones. windows os required features that gave developers and administrators the option to perform tasks remotely. microsoft responded in part with active directory services interface (adsi). adsi provides a single set of directory interfaces for accessing and managing network resources. so for instance, an administrator could change user permissions or add a user to a network, independent of network environment, using a web interface or a vb program. caveatplease keep in mind that you are going to modify the basics of the windows nt security model. you should be very alert when dealing with adsi. keep in mind that a simple mistype could mean reformatting and reinstalling your system. don't do it on a operational machine! please know that i have tried to make the following code as accurate as possible. yet i can't guarantee their outcome. so please don't just copy and paste. i know it is very attractive, but it could cause you to spend the next couple of hours looking at a very appealing windows installation screen. windows security account managerthe security account manager (sam) is the portion of windows which registers and holds all user information and knows all the default configuration settings. our first meeting with sam entails the process of creating a user. this applies to windows 2000 as well as windows nt 4.0. note: in order for the following code to work, administrator rights are required. adding a user to the sam<%1. adduser"newuser","mydomain"2. 3. sub adduser(struser,strdomain)4. dim computer5. dim user6.7. set computer = getobject("winnt://" & strdomain)8. set user = computer.create("user",struser)9. user.setinfo10. end sub%>this code can be activated by calling it anywhere in the asp page (line 1). also, make sure to spell winnt like the example given in line 7. adsi is very case sensitive and will refuse to work if you spell it differently. as you can see there are no attributes given; this user is created without a password. let's do something about that. <%1. adduser"newuser","mydomain","new user","adsi","our best employee"2. 3. sub adduser(struser,strdomain,strfullname,strpassword,strdesc)4. dim computer5. dim user6.7. set computer = getobject("winnt://" & strdomain)8. set user = computer.create("user",struser)8. user.fullname = strfullname9. user.description = strdesc10. call user.setpassword(strpassword)11. user.setinfo12. end sub%>as you can see, i added more than just a password. i also added the fullname and the description. these aren't really important if you have a system with 5 users, but large corporations usually have a policy about that. please be advised that the above code is for adding a new user. i will cover modifying an existing user in a future article. the problem about adsi is that you can't guess the code. it's not as easy as only punching up user.[attribute_name]. next stop is the userflags. these control options such as "password never expires" and "account disabled". <%1.userflags "newuser","mydomain",0,false,true,true,true2. 3. sub userflags(struser,strdomain,strpassexpires,strnochange,strnoexpire, & _ strdisable,strlocked)4.dim user5.dim flags6.7.set user = getobject("winnt://" & strdomain & "/" & struser & ",user")8.flags = user.get("userflags")9.10.user.put "passwordexpired",strpassexpires11.user.accountdisabled = strdisable12.if strnochange = "true" then 13.user.put "userflags", flags or &h0004014.end if15.if strnoexpire = "true" then16.user.put "userflags", flags or &h1000017.end if18.user.isaccountlocked = strlocked19.end sub%>in the example above i gave my new user some restrictions. the outcome of this subroutine is that my new user will have a valid password (password isn't expired because it's set on 0. if you change it to 1, the password isn't valid anymore. if the password is expired, the user will be forced to change it at the next login). he will be unable to change his own password; his password will never expire; and his account is disabled and locked. in order to change, this you should modify the subroutine call. so now we have a new user with all the default settings. maybe this is enough for your home situation, but many companies want to set more boundaries for their users. also, a lot of companies have the personal settings of their users stored on a separate network drive. adsi allows you to make sure your new users have the same configuration as every other employee. <%1. userconfig "newuser","mydomain","c:\myprofiles\","myscript.cmd","c:\","z:\", & _ #mm/dd/yyyy#,"true"2.3.sub userconfig(struser,strdomain,strprofile,strscript,strhomedir, & _ strhomedirdrive,straccountexpire,strpassrequired)4.dim user5.dim flags6.7.set user = getobject("winnt://" & strdomain & "/" & struser & ",user")8.9.user.profile = strprofile10.user.loginscript = strscript11.user.homedirectory = strhomedir12.user.put("homedirdrive"),strhomedirdrive13.user.accountexpirationdate = straccountexpire14.user.passwordrequired = strpassrequired15.16.end sub%>now we have all the information we need to make a new user. i'm not going to explain these options because if you don't know them, you don't need to use them. the three subroutines we created can be used perfectly in combination with each other (see below). remember, please test on a non-operational system first! look out for little mistakes and adjust the code so it applies to your situation. just in case: i cannot be held responsible for any damage that could occur before, during or after implementing and using this code. <%1.adduser"newuser","mydomain","new user","adsi","our best employee"2.userflags "newuser","mydomain",0,false,true,true,true3.userconfig "newuser","mydomain","c:\myprofiles\","myscript.cmd","c:\","z:\", & _ #mm/dd/yyyy#,"true"4.5.6.sub adduser(struser,strdomain,strfullname,strpassword,strdesc)7.dim computer,user8.set computer = getobject("winnt://" & strdomain)9.set user = computer.create("user",struser)10.user.fullname = strfullname11.user.description = strdesc12.call user.setpassword(strpassword)13.user.setinfo14.end sub15.16.sub userflags(struser,strdomain,strpassexpires,strnochange,strnoexpire, & _ strdisable,strlocked)17.dim user,flags18.set user = getobject("winnt://" & strdomain & "/" & struser & ",user")19.flags = user.get("userflags")20.user.put "passwordexpired",strpassexpires21.user.accountdisabled = strdisable22.if strnochange = "true" then 23.user.put "userflags", flags or &h0004024.end if25.if strnoexpire = "true" then26.user.put "userflags", flags or &h1000027.end if28.user.isaccountlocked = strlocked29.end sub30.31.sub userconfig(struser,strdomain,strprofile,strscript,strhomedir, & _ strhomedirdrive,straccountexpire,strpassrequired)32.dim user,flags33.set user = getobject("winnt://" & strdomain & "/" & struser & ",user")34.user.profile = strprofile35.user.loginscript = strscript36.user.homedirectory = strhomedir37.user.put("homedirdrive"),strhomedirdrive38.user.accountexpirationdate = straccountexpire39.user.passwordrequired = strpassrequired40.end sub%>about the authorremie bolte is a student at communicatiesystemen in the netherlands. he has experience with vb, asp, vbscript and sql. his goal in life is to clean up the internet and show people how it can benefit their needs. remie can be reached at r.bolte@vinrem.nl.

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.