Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

populate listbox with domain users

Posted on 2003-12-10
12
Medium Priority
?
820 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 800 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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…

721 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