大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> ASP专区 -> 用ASP/ADSI显示NT系统中的用户和组列表

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

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

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 scurrentgroupdim sdomainnamescurrentgroup = request.querystring("group")sdomainname = request.querystring("domain")'change the following line so that sdomainname is 'your machine name or domain nameif 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 <> "" thenresponse.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 listfunction listgroups(sdomainname, sselectedgroup, sonchangescript)dim sselectlisthtmldim sgroupnamesselectlisthtml = "<select name=""group"" id=""group"" "sselectlisthtml = sselectlisthtml & "onchange=""" & sonchangescript & """>" & vbcrlfsselectlisthtml = sselectlisthtml & "<option value="""">---------------"sselectlisthtml = sselectlisthtml & "select a group"sselectlisthtml = sselectlisthtml & "---------------</option>" & vbcrlfset domain = getobject("winnt://" & sdomainname)for each member in domainif member.class = "group" thensgroupname = nullsgroupname = member.nameif sgroupname = sselectedgroup thensselectlisthtml = sselectlisthtml & "<option selected value=""" & sgroupname & """>"sselectlisthtml = sselectlisthtml & sgroupname & "</option>" & vbcrlfelsesselectlisthtml = sselectlisthtml & "<option value="""sselectlisthtml = sselectlisthtml & sgroupname & """>" & sgroupname & "</option>" & vbcrlfend ifend ifnextsselectlisthtml = sselectlisthtml + "</select>" & vbcrlflistgroups = sselectlisthtmlend 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 groupfunction listusers(sdomainname, sgroupname)dim suserlistdim smyparentset group = getobject("winnt://" & sdomainname & "/" & sgroupname)for each member in group.memberson error resume nextsmyparent = member.parentsmyparent = right(smyparent, len(smyparent) - instrrev(smyparent, "/"))if member.class = "user" thensuserlist = 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" thensuserlist = 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 ifnextif suserlist = "" thensuserlist = "<p>this group does not contain any users</p>"end iflistusers = suserlistend 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.

热门阅览

最新排行

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