日期:2009-07-23  浏览次数:21081 次

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 machine's 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 th