Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old March 30th, 2006, 01:52 PM
olandir olandir is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 7 olandir User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 57 m 22 sec
Reputation Power: 0
Need help using ASP/ADO/ADSI to pull information from Active Directory

I know there are probably several dozen resources on this but I haven't been able to find anything simple I could just follow or copy.

I'd like to use ASP (preferably just regular ASP, not .NET) to pull out a few properties of each user object in one Organization Unit of my active directory (and the sub-OUs below it)... that's it.... I just want to be able to get about 7 pieces of information. I don't need to edit active directory or anything like that.

I understand you can pull information using ADO/ADSI interface, but I can't figure out how to do it. All the examples I've found seem to be for WScript instead of ASP. The ones I do find for ASP seem to be missing important things, like they assume I should have already done something or had some other code.

If someone could just give me a semi complete sample code that pulls this information and writes it out, I do know enough ASP that I can make adjustments as needed to format it the way I want. I really just want to be able to copy some code that works and then make the adjustments from there.

I can pay someone for this code if that'll get me a response... can't pay much, but it would be worth it. Just reply here to let me know.

Here is some information about my domain/site (if you need more to help me, just let me know).

domain = stjosephsvilla.net
domain controller = sjv-domain-2
ou = Staff Accounts
properties I want to retrieve (from user objects only)
-name
-title
-department
-mail
-mobile
-pager
-telephoneNumber

Last edited by olandir : March 31st, 2006 at 01:51 PM. Reason: Trying to get responses

Reply With Quote
  #2  
Old April 18th, 2006, 11:10 AM
schillerdb schillerdb is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 1 schillerdb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m 39 sec
Reputation Power: 0
Actually something fairly decent on microsoft for this

I found two articles from the Scripting Guys on Microsoft's Tales from the Script.

The articles Are:
Dude, Where's My Printer: Using Scripts to Search Active Directory (Part 1)

Dude, Where's My Printer: Using Scripts to Search Active Directory (Part 2 of 2)

It is vbscript, which is bascially asp, so just enclose the code withing <%...%>. It requires, of course, that you replace your LDAP string (i.e. CN, DC, etc.).

It is a good start.

Reply With Quote
  #3  
Old April 18th, 2006, 11:53 AM
olandir olandir is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 7 olandir User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 57 m 22 sec
Reputation Power: 0
Wscript and ASP ARE NOT THE SAME

Quote:
Originally Posted by schillerdb
I found two articles from the Scripting Guys on Microsoft's Tales from the Script.

The articles Are:
Dude, Where's My Printer: Using Scripts to Search Active Directory (Part 1)

Dude, Where's My Printer: Using Scripts to Search Active Directory (Part 2 of 2)

It is vbscript, which is bascially asp, so just enclose the code withing <%...%>. It requires, of course, that you replace your LDAP string (i.e. CN, DC, etc.).

It is a good start.



I put this code in a .vbs file and ran it, and it works PERFECTLY

Code:
On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

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 
objCommandProperties("Sort On") = "Name"

objCommand.CommandText = _
    "SELECT Name FROM 'LDAP://ou=Servers,dc=stjosephsvilla,dc=net' WHERE objectCategory='user'"  
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields("Name").Value
    objRecordSet.MoveNext
Loop


However, I put this code in an ASP page and tried to open the page and I get NOTHING but a blank page. It idles for like 2 minutes, then I get nothing. Then I get no response from Internet Explorer. Obviously ASP and Wscript are different... I was clever enough to change Wscript.echo to Response.write, but that must not be the only difference.

Code:
On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

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 
objCommandProperties("Sort On") = "Name"

objCommand.CommandText = _
    "SELECT Name FROM 'LDAP://ou=Servers,dc=stjosephsvilla,dc=net' WHERE objectCategory='user'"  
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Response.write objRecordSet.Fields("Name").Value
    objRecordSet.MoveNext
Loop

Reply With Quote
  #4  
Old May 22nd, 2006, 12:36 AM
dstove dstove is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 1 dstove User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 42 sec
Reputation Power: 0
This is what I use - in ASP on IIS 6

Hi there,
If you haven't has an answer yet, try this. It works for me...

Code:
  Sub GetUsers
  dim con,com, domainPath, rs

  Set con = CreateObject("ADODB.Connection")
  Set com =   CreateObject("ADODB.Command")
  domainPath = "LDAP://mydomain.com"
  'Open the ADSI Connection.
  con.Provider = "ADsDSOObject"
  'Credentials  
  con.Properties("User ID") = "Username"
  con.Properties("Password") = "Password"
  con.Open "Active Directory Provider"
  Set Com.ActiveConnection = con
  Com.CommandText = "<" & domainPath & ">;(&(objectCategory=person)(objectClass=user));ADsPath  ,name,telephoneNumber,title,physicalDeliveryOffice  Name,department,objectCategory,objectClass;subtree  "  
  Com.Properties("Page Size") = 64
  Com.Properties("Timeout") = 30 'seconds
  Com.Properties("Cache Results") = False   
  Set rs = Com.Execute
  Response.Write "<Table>"
  do until rs.eof
    Response.Write "<TR>"
    Response.Write "<TD>" & rs("Name").value & "</TD>"
    Response.Write "<TD>" & rs("title").value & "</TD>"
    Response.Write "<TD>" & rs("telephoneNumber").value & "</TD>"
    Response.Write "<TD>" & rs("department").value & "</TD>"
    Response.Write "</TR>"
    rs.movenext
  loop
  Response.Write "</Table">
  con.Close
  set rs = nothing  
  set com = nothing
  set con = nothing
  end sub


For a list of all the properties you can select, try http://www.rlmueller.net/References/ADUCProperties.xls

cheers
Dominic

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Need help using ASP/ADO/ADSI to pull information from Active Directory


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT