I found a file on the web that will allow you to enumerate groups but it was an .hta and the top level admins won't allow this. I need to give managers access to the groups so that when a new user is created they can tell me who they want their account to be modeled after. The html app works great as a .hta file but when it is saved as a web page it won't list the members of any groups. I get an error on line 182: "ActiveX component can't create object: 'GetObject'" Here is the line that throws the error: "Set objRootDSE = GetObject("LDAP ://RootDSE")" Here is the code:
[html]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Group Enumerator</title>
<style type="text/css">
/* Default CSS Stylesheet for a new Web Application project */
body{background-color:#cdd4e6; margin:20 20 20 0; color:#444444;}
td{font-family:Arial, Helvetica, sans-serif; font-size:11px;}
select{font-family:Arial, Helvetica, sans-serif; font-size:11px;}
input{font-family:Arial, Helvetica, sans-serif; font-size:11px;}
a{font-family:Arial, Helvetica, sans-serif; font-size:11px;color :#444444;}
/* Custom */
td.header{backg round-color:#7f92bf; color:#ffffff; font-size: 20px; padding-left:15px;}
td.content{padd ing:15 15 15 15; background-color:#ffffff;}
td.title{color: #7f92bf; font-size:10px;}
td.error{color: #ff0000}
/* Tabs */
a.tablink{font-weight:bold;tex t-decoration:none ;}
.tabline{border-bottom:1px solid #CCCCCC}
.tab{border-top:1px solid #CCCCCC;border-right:1px solid #CCCCCC;border-bottom:1px solid #CCCCCC;padding :3 5 3 5;border-left:1px solid #CCCCCC;backgro und-color:#eeeeee}
.tabactive{bord er-top:1px solid #CCCCCC;border-right:1px solid #CCCCCC; border-left:1px solid #CCCCCC;padding :3 5 3 5;}
/* Grid */
td.gridheader{p adding:3 3 3 3; font-weight:bold; background-color:#eeeeee;}
td.gridcell{pad ding:3 3 3 3;border-bottom:1px solid #eeeeee}
</style>
[/html]
[html]
<form id="frmPage" action="">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" >
<tr>
<td height="50" class="header"> Group Enumerator</td>
</tr>
<tr>
<td class="content" height="100%" valign="top">
<table cellSpacing="0" cellPadding="0" border="1">
<tr>
<td class="title">D istribution Groups</td>
<td class="title">S ecurity Groups</td>
<td class="title">G roup Membership</td>
</tr>
<tr>
<td class="title"> <select size="20" name="boxDistri bution" onChange="vbscr ipt:Get_Distrib ution"></select></td>
<td class="title"> <select size="20" name="boxSecuri ty" onChange="vbscr ipt:Get_Securit y"></select></td>
<td class="title"> <select size="20" name="objMember ship" ></select></td>
</tr>
</td>
</table>
<table cellSpacing="0" cellPadding="0" border="0">
<tr>
<td>
<input id=QuitButton class="button" type="button" value="Quit" name="Quit_butt on" onClick="Quit_H TA">
</td>
<td>
<!--
<input id=DistButton class="button" type="button" value="Export Distrbution groups to Excel" name="Dist_butt on" onClick="Export _dist">
-->
</td>
<td>
<!--
<input id=SecButton class="button" type="button" value="Export Security groups to Excel" name="Sec_butto n" onClick="">
-->
</td>
<td>
<input id=MemButton class="button" type="button" value="Export Results" name="Mem_butto n" onClick="PopExc elGroups">
</td>
</tr>
</table>
</form>
</body>
</html>
[/html]
[html]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Group Enumerator</title>
<style type="text/css">
/* Default CSS Stylesheet for a new Web Application project */
body{background-color:#cdd4e6; margin:20 20 20 0; color:#444444;}
td{font-family:Arial, Helvetica, sans-serif; font-size:11px;}
select{font-family:Arial, Helvetica, sans-serif; font-size:11px;}
input{font-family:Arial, Helvetica, sans-serif; font-size:11px;}
a{font-family:Arial, Helvetica, sans-serif; font-size:11px;color :#444444;}
/* Custom */
td.header{backg round-color:#7f92bf; color:#ffffff; font-size: 20px; padding-left:15px;}
td.content{padd ing:15 15 15 15; background-color:#ffffff;}
td.title{color: #7f92bf; font-size:10px;}
td.error{color: #ff0000}
/* Tabs */
a.tablink{font-weight:bold;tex t-decoration:none ;}
.tabline{border-bottom:1px solid #CCCCCC}
.tab{border-top:1px solid #CCCCCC;border-right:1px solid #CCCCCC;border-bottom:1px solid #CCCCCC;padding :3 5 3 5;border-left:1px solid #CCCCCC;backgro und-color:#eeeeee}
.tabactive{bord er-top:1px solid #CCCCCC;border-right:1px solid #CCCCCC; border-left:1px solid #CCCCCC;padding :3 5 3 5;}
/* Grid */
td.gridheader{p adding:3 3 3 3; font-weight:bold; background-color:#eeeeee;}
td.gridcell{pad ding:3 3 3 3;border-bottom:1px solid #eeeeee}
</style>
[/html]
Code:
<script language="VBScript">
Const DOMAIN = "luiginos.com"
'ou's to ignore when making groups available security related or obsolete
' Const OUS_TO_IGNORE = "OU=this,OU=that,OU=theother,DC=WINDOWSITPRO,DC=tld OU=obsolete,DC=WINDOWSITPRO,DC=tld"
Const OUS_TO_IGNORE = ""
Dim Searchtype
Dim strUserName
Dim objUser
Dim bUserLoaded
Dim arrUserGroups
Dim intSecCount
Dim intDistCount
Dim strGroupChosen
bUserLoaded = False
' ======= Standardized Arrays
Dim arrSecGroup(500)
Dim arrDistGroup(500)
Sub window_Onload
Const ADS_SCOPE_SUBTREE = 2
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Sort On") = "name"
objCommand.CommandText = _
"<LDAP://" & DOMAIN & ">;(&(objectCategory=GROUP));Name,grouptype,distinguishedName;Subtree"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
intSecCount = 1
intDistCount = 1
Do Until objRecordSet.EOF
tmpDGN = objRecordSet.Fields("distinguishedName").Value
If InStr(1,OUS_TO_IGNORE,Right(tmpDGN, Len(tmpDGN) - InStr(1,tmpDGN,",",1)),1) = 0 Then
If objRecordSet.Fields("Grouptype").Value And ADS_GROUP_TYPE_SECURITY_ENABLED Then
arrSecGroup(intSecCount) = objRecordSet.Fields("Name").Value
intSecCount = intSecCount + 1
Else
arrDistGroup(intDistCount) = objRecordSet.Fields("Name").Value
intDistCount = intDistCount + 1
End If
End If
objRecordSet.MoveNext
Loop
'fill up group boxes
FillGroups arrSecGroup, intSecCount, document.all.boxSecurity
FillGroups arrDistGroup, intdistCount, document.all.boxDistribution
Set objConnection = Nothing
Set objCommand = Nothing
Set objRecordSet = Nothing
End Sub
Sub StartUserHTA
Set WshShell = CreateObject("WScript.Shell")
strCmdLine = ".\HD-Dash-USER.hta"
WSHShell.Run strCmdLine,8
End Sub
Sub Get_Distribution
document.all.boxSecurity.SelectedIndex = Null
For Each objOption In document.all.objMembership.Options
objOption.RemoveNode
Next
strGroupChosen = "Distribution group - " & arrDistGroup(document.all.boxdistribution.selectedIndex)
EnumMembers arrDistGroup(document.all.boxdistribution.selectedIndex), "", ""
End Sub
Sub Get_Security
document.all.boxdistribution.SelectedIndex = Null
For Each objOption In document.all.objMembership.Options
objOption.RemoveNode
Next
strGroupChosen = "Security group - " & arrSecGroup(document.all.boxSecurity.selectedIndex)
EnumMembers arrSecGroup(document.all.boxSecurity.selectedIndex), "", ""
End Sub
' What: Fills in Group boxes both Security and ditribution
' Input: arrGroup is the array to fill with, intGroupCount is how many itmes in the array and PaneName
' is where the information should be place
' output: Security and distrubution panes are filled.
Sub FillGroups (arrGroup, intGroupCount, PaneName)
For Each objOption In PaneName.Options
objOption.RemoveNode
Next
Set objOption = document.createElement("OPTION")
objOption.Text = "<CHOOSE A GROUP>"
objOption.Value = 0
PaneName.Add(objOption)
For intIncrement = 1 To intGroupCount
If arrGroup(intIncrement) <> "" Then
Set objOption = document.createElement("OPTION")
objOption.Text = arrGroup(intIncrement)
objOption.Value = i
PaneName.Add(objOption)
End If
Next
Set objOption = Nothing
end Sub
Sub EnumMembers(strName, strOffset, strGOffset)
' Recursive subroutine to enumerate members of a group,
' including nested group memberships.
Dim strFilter, strQuery, objRecordSet, k, objMember, objCommand
Dim strDN, intCount, blnLast, intLowRange, objConnection
Dim intHighRange, intRangeStep, objField
Dim iCount, objGroup, strAttributes
Dim strNTName, objRootDSE, strDNSDomain
Dim strBase, objGroupList
Dim objMemList
strAttributes = "member, sn"
If strGOffset = "" Then
strGOffset = "+"
End If
Set objRootDSE = GetObject("LDAP://RootDSE")
strBase = "<LDAP://" & objRootDSE.Get("DefaultNamingContext") & ">"
' Filter on objects of class "group" and specified name.
strFilter = "(&(ObjectCategory=group)" & "(ObjectClass=group)" & "(Name=" & strName & "))"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
' Use ADO to search Active Directory.
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open = "Active Directory Provider"
objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 100
objCommand.Properties("Sort On") = "sn"
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
objCommand.CommandText = strQuery
Set objRecordSet = objCommand.Execute
Do Until objRecordSet.EOF
For Each objField In objRecordSet.Fields
If IsArray(objField.Value) Then
objMemList = SingleSorter(objField.Value)
i = 1
For Each strDN In objMemList
Set objGroup = GetObject("LDAP://" & strDN & "")
IF LCase(objGroup.Class) = "group" Then
Set objOption = document.createElement("OPTION")
objOption.Text = strGOffset & objGroup.cn
objOption.Value = objGroup.cn
document.all.objMembership.Add(objOption)
strOffset = strOffset + "-"
strGOffset = strGOffset + "+"
Call EnumMembers(objGroup.cn, strOffset, strGOffset)
Else
Set objOption = document.createElement("OPTION")
objOption.Text = strOffset & objGroup.cn
objOption.Value = objGroup.cn
document.all.objMembership.Add(objOption)
END If
intCount = intCount+1
iCount=iCount+1
Next
End If
Next
objRecordSet.MoveNext
Loop
If strOffset <> "" Then
strOffset = Right(strOffset, Len(strOffset) - 1)
End If
If strGOffset <> "" Then
strGOffset = Right(strGOffset, Len(strGOffset) - 1)
End If
End Sub
</script>
<form id="frmPage" action="">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" >
<tr>
<td height="50" class="header"> Group Enumerator</td>
</tr>
<tr>
<td class="content" height="100%" valign="top">
<table cellSpacing="0" cellPadding="0" border="1">
<tr>
<td class="title">D istribution Groups</td>
<td class="title">S ecurity Groups</td>
<td class="title">G roup Membership</td>
</tr>
<tr>
<td class="title"> <select size="20" name="boxDistri bution" onChange="vbscr ipt:Get_Distrib ution"></select></td>
<td class="title"> <select size="20" name="boxSecuri ty" onChange="vbscr ipt:Get_Securit y"></select></td>
<td class="title"> <select size="20" name="objMember ship" ></select></td>
</tr>
</td>
</table>
<table cellSpacing="0" cellPadding="0" border="0">
<tr>
<td>
<input id=QuitButton class="button" type="button" value="Quit" name="Quit_butt on" onClick="Quit_H TA">
</td>
<td>
<!--
<input id=DistButton class="button" type="button" value="Export Distrbution groups to Excel" name="Dist_butt on" onClick="Export _dist">
-->
</td>
<td>
<!--
<input id=SecButton class="button" type="button" value="Export Security groups to Excel" name="Sec_butto n" onClick="">
-->
</td>
<td>
<input id=MemButton class="button" type="button" value="Export Results" name="Mem_butto n" onClick="PopExc elGroups">
</td>
</tr>
</table>
</form>
</body>
</html>
[/html]