Solved

populate listbox with domain users

Posted on 2003-12-10
12
818 Views
Last Modified: 2010-04-06
How do I populate a listbox (on a form) with all users from my domain? I have some vbscript as a starting point that will list the current user, but how do I get this to iterate through each user and populate my listbox? My plan is to have a seperate listbox for each location. Also I'm unsure if this script will work directly in ASP.

' use ADSI to get name office location
Const E_ADS_PROPERTY_NOT_FOUND = &H8000500D
Dim objDSE, objUser, varPropValue, arrPropValues, i
Dim strLoginHours, strByte
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objDSE = GetObject("LDAP://rootDSE")
Set objUser = GetObject("LDAP://CN=" & WshNetwork.UserName & ",CN=Users" & "," & objDSE.Get("defaultNamingContext"))
thename = objUser.Get("sAMAccountName")
location = objUser.OfficeLocations
0
Comment
Question by:tariqf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 3
12 Comments
 
LVL 19

Expert Comment

by:Rimvis
ID: 9911629
I woult suggest using ADO driver for Active Directory instead

Here's sample code:


Dim rstUsers
Dim objDSE, strNamingContext

Set objDSE = GetObject("LDAP://rootDSE")
strNamingContext = objDSE.Get("defaultNamingContext")
Set objDSE = Nothing

set rstUsers= Server.CreateObject("ADODB.Recordset")
rstUsers.Open , "SELECT sAMAccountName FROM 'LDAP://CN=Users," & strNamingContext  & "' WHERE objectClass='user' ORDER BY name", "Provider=ADsDSOObject"

While Not rstUsers.EOF
   'do whatever you want
Whend

rstUsers.Close
Set rstUsers = Nothing


rstUsers.Close
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 9911633
Sorry, forgot MoveNext

While Not rstUsers.EOF
   'do whatever you want
   rstUsers.MoveNext
Whend
0
 
LVL 1

Author Comment

by:tariqf
ID: 9911855
Hi, I have tried your response, but I get a "type missmatch" on this line;

rstUsers.Open , "SELECT sAMAccountName FROM 'LDAP://CN=Users," & strNamingContext  & "' WHERE objectClass='user' ORDER BY name", "Provider=ADsDSOObject"

any ideas? PLease note I am running this with wsh before I migrate it to ASP so I removed the server in server.createobject
0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 19

Expert Comment

by:Rimvis
ID: 9911880
Oops, typo. Remove comma after rstUsers.Open
Should be

rstUsers.Open "SELECT sAMAccountName FROM 'LDAP://CN=Users," & strNamingContext  & "' WHERE objectClass='user' ORDER BY name", "Provider=ADsDSOObject"
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 9911890
Also, you would want to change ordering.

rstUsers.Open "SELECT sAMAccountName FROM 'LDAP://CN=Users," & strNamingContext  & "' WHERE objectClass='user' ORDER BY sAMAccountName", "Provider=ADsDSOObject"
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 9911907
Hm, and another error. Remove last "rstUsers.Close".

My apologies for this mess, I remade this sample from my project, so there were a few errors during copy-paste-editing :o/
0
 
LVL 1

Author Comment

by:tariqf
ID: 9912043
this may seem like a stupid question but how to I refer to each user? e.g. wscript.echo sAMAccountName
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 9912127
wscript.echo rstUsers("sAMAccountName").Value
0
 
LVL 19

Accepted Solution

by:
Rimvis earned 200 total points
ID: 9912140
And for ASP:

Response.Write rstUsers("sAMAccountName").Value & "<br>"
0
 
LVL 1

Author Comment

by:tariqf
ID: 9912261
Hi, thanks for your help, I cannot seem to get the officelocation as I used to though - I have tried using

SELECT sAMAccountName,OfficeLocations FROM 'LDAP://CN=Users...

but this doesn't work. Can you help please?
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 9912473
physicalDeliveryOfficeName?
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 9912494
Check this link for complete list of Organizational-Person class properties:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adschema/ad/win2k_c_organizationalperson.asp
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question