欢迎光临
我们一直在努力

用ASP/ADSI显示NT系统中的用户和组列表

建站超值云服务器,限时71元/月

introduction

the asp code described in this article will allow you to find a list of windows nt groups in a specific

domain or on a specific computer, then view a list of users and groups within that group.

how it works

the asp code uses microsoft抯 active directory service interfaces (adsi). adsi is a directory system that

makes it straightforward to administer and obtain information from a variety of data stores on the system

(e.g. exchange server, internet information server, and windows nt itself). adsi can run on windows 95,

98, nt 4.0 and windows 2000. due to the lack of security features in windows 95 and 98 it is advisable to

not run adsi services on these operating systems. the examples described here have been tested with

windows nt 4.0.

adsi is particularly useful under windows 2000, as it allows access to the windows 2000 active directory.

the active directory is one of the cornerstones of windows 2000, so it is worth getting to grips with. if

you want to learn adsi, there are a number of tutorials listed at the bottom of this article.

in order to get the examples to work, you will need to install adsi. the current version (2.5) is a free

download from microsoft抯 website (see links at the bottom of this article).

the code

there are four parts to the example page, which should be saved as usergroupbrowser.asp.

the first part of the page should be added to above the opening <html> tag:

<%

dim scurrentgroup

dim sdomainname

scurrentgroup = request.querystring("group")

sdomainname = request.querystring("domain")

change the following line so that sdomainname is

your machine name or domain name

if sdomainname = "" then sdomainname = "mydomain"

%>

note that the 8th line of this code should be changed to replace mydomain with the name of your windows nt

domain (or your machines name).

the second piece of code should be placed in the <body> part of the asp document. it contains calls to the

functions that display the groups within a domain and also the users within a specific group:

<p>exploring the domain <%=sdomainname%></p>

<form name="frmgroupselector" action="usergroupbrowser.asp" method="get">

<input type="hidden" name="domain" value="<%=sdomainname%>">

<%=listgroups(sdomainname, scurrentgroup, "submitfrm()")%>

</form>

<%

if scurrentgroup <> "" then

response.write listusers(sdomainname, scurrentgroup)

end if

%>

the third piece of code is a small piece of javascript containing a function to submit the group select

list if a group has been selected:

<script language="javascript"><!–

function submitfrm() {

if (document.frmgroupselector.group.options[document.frmgroupselector.group.selectedindex].value !

= )

{

document.frmgroupselector.submit();

}

}

//–></script>

finally, there are two asp functions: listgroups and listusers. the code for these is shown below:

<%

function to create a select list containing a list of groups within a computer

or domain. function must be supplied with three arguments:

sdomainname: the domain name or computer name

sselectedgroup: the name of the group that should have the selected attribute

sonchangescript: the name of the javascript function that should be executed

when the onchange event is triggered for this select list

function listgroups(sdomainname, sselectedgroup, sonchangescript)

dim sselectlisthtml

dim sgroupname

sselectlisthtml = "<select name=""group"" id=""group"" "

sselectlisthtml = sselectlisthtml & "onchange=""" & sonchangescript & """>" & vbcrlf

sselectlisthtml = sselectlisthtml & "<option value="""">—————"

sselectlisthtml = sselectlisthtml & "select a group"

sselectlisthtml = sselectlisthtml & "—————</option>" & vbcrlf

set domain = getobject("winnt://" & sdomainname)

for each member in domain

if member.class = "group" then

sgroupname = null

sgroupname = member.name

if sgroupname = sselectedgroup then

sselectlisthtml = sselectlisthtml & "<option selected value=""" & sgroupname & """>"

sselectlisthtml = sselectlisthtml & sgroupname & "</option>" & vbcrlf

else

sselectlisthtml = sselectlisthtml & "<option value="""

sselectlisthtml = sselectlisthtml & sgroupname & """>" & sgroupname & "</option>" & vbcrlf

end if

end if

next

sselectlisthtml = sselectlisthtml + "</select>" & vbcrlf

listgroups = sselectlisthtml

end function

%>

<%

function to list the users and groups within a specific user group.

function must be supplied with two arguments:

sdomainname: the domain name or computer name

sgroupname: the name of the user group

function listusers(sdomainname, sgroupname)

dim suserlist

dim smyparent

set group = getobject("winnt://" & sdomainname & "/" & sgroupname)

for each member in group.members

on error resume next

smyparent = member.parent

smyparent = right(smyparent, len(smyparent) – instrrev(smyparent, "/"))

if member.class = "user" then

suserlist = suserlist & "<b>" & member.name & "</b><br>"

suserlist = suserlist & " full name: " & member.fullname & "<br>"

suserlist = suserlist & " description: " & member.description & "<br>"

suserlist = suserlist & " account disabled: " & member.accountdisabled & "<br>"

suserlist = suserlist & "<p>"

elseif member.class = "group" then

suserlist = suserlist & "<b><a href=""usergroupbrowser.asp?"

suserlist = suserlist & "group=" & server.urlencode(member.name)

suserlist = suserlist & "&domain=" & server.urlencode(smyparent)

suserlist = suserlist & """>" & member.name & "</a></b>< br>"

suserlist = suserlist & " description: " & member.description & "<br>"

suserlist = suserlist & "<p>"

end if

next

if suserlist = "" then

suserlist = "<p>this group does not contain any users</p>"

end if

listusers = suserlist

end function

%>

the first function (listgroups) will generate the html required for a select list containing a list of all

the groups within a specified windows domain (or an individual computer). it achieves this by first

binding the domain object to the active directory object for the specified windows domain or individual

machine. it then enumerates the list of members within the domain, and if the member is found to be a

group it adds an option tag to the select list.

the second function (listusers) will display a list of users and groups within a specific group [under

windows nt it is possible to make groups members of other groups, such as adding power users to the

administrators group].

the listusers function will display a number of attributes of users it finds; specifically their full

name, description, and whether or not their account is disabled. further attributes can be obtained using

adsi – a full list is shown in microsoft抯 adsi documentation (link at the bottom of this article).

note that on error resume next should be used when using active directory, because the asp document will

stop being processed if a certain attribute cannot be found.

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 用ASP/ADSI显示NT系统中的用户和组列表
分享到: 更多 (0)