Announcement

Collapse
No announcement yet.

AD user info pull via asp vbscript

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • AD user info pull via asp vbscript

    I am fairly new to asp and scripting but here is my project.
    Have a vbs file, converted over to asp. But I've probably been staring at it so long I can't see what might be wrong or how to fix it.
    Can somebody please verify or suggest corrections?

    Thanks!

    I started with disabling nearly everything, and am slowly enabling portions to see what errors out. The point I'm at right now results in the error 'Object doesn't support this property or method: 'ActiveConnection' I have received quite a few other Object doesn't support errors prior to now, but I can't quite figure out what tiny thing I might have changed to make it go away.



    <%@ Language="VBScript" %>

    <%

    Dim strUserName

    Dim adoCommand, adoConnection, strBase, strFilter, strAttributes, rs, com, intUAC

    Dim objRootDSE, strRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN

    Dim str_a, str_b, str_c, objNet

    Dim arrUser, strNTUser
    arrUser = Split(Request.ServerVariables("LOGON_USER"), "\")
    strNTUser = arrUser(1)

    response.write(strNTUser)

    '' Setup ADO objects.
    set objRootDSE = getObject("LDAP://rootDSE")
    strRootDSE = objRootDSE.Get("defaultNamingContext")

    response.write(strRootDSE)
    'objRootDSE = Nothing

    set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open("Active Directory Provider")

    adoCommand = CreateObject("ADODB.Command")
    adoCommand.ActiveConnection = adoConnection

    'adoCommand.CommandText = "SELECT mail,title,department,cn,name,sAMAccountName,displ ayname FROM 'LDAP://" & strRootDSE & "' " _
    '& "WHERE sAMaccountName='" & strNTUser & "'"


    ''rs = adoCommand.Execute
    ''While Not rs.eof
    ' ' intUAC = rs.fields("name")
    ''End While
    'adoCommand.CommandText = strQuery
    'adoCommand.Properties("Page Size") = 100
    'adoCommand.Properties("Timeout") = 30
    'adoCommand.Properties("Cache Results") = False



    '' Run the query.
    'adoRecordset = adoCommand.Execute
    'response.write(adoCommand)


    '' Enumerate the resulting recordset.
    ''Do Until adoRecordset.EOF

    '' Retrieve values and display.
    'strName = adoRecordset.Fields("sAMAccountName").Value
    'str_a = adoRecordset.Fields("displayName").Value
    'str_b = adoRecordset.Fields("name").Value
    'str_c = adoRecordset.Fields("title").Value

    'strCN = adoRecordset.Fields("cn").value

    'Response.Write("NT Name: " & strName & ", Common Name: " & strCN)
    'Response.Write("displayname " & str_a & ", email " & str_b & ", " & str_c)

    '' Move to the next record in the recordset.
    ''adoRecordset.MoveNext()
    ''Loop



    '' Clean up.

    'adoRecordset.Close()

    'adoConnection.Close()
    %>

    <head>
    <title>Untitled Page</title>
    </head>
    <body>

    <p>Field0: <%=strNTUser%></p>
    <p>Field1: <%=str_a%></p>
    <p>Field2: <%=str_b%></p>
    <p>Field3: <%=str_c%></p>
    <p>Field4: <%=strCN%></p>


    </body>
    </html>
    Last edited by militarymedic22; 12th December 2007, 05:01.

  • #2
    Re: AD user info pull via asp vbscript

    With what i understood, you are trying to display AD User Details in a webpage, i did not corrected your code, but you can use this one. I hope this is what you want

    Prasad
    ----------

    Code:
    <STYLE TYPE="text/css">
    <!--
    	A:link {color:"blue";text-decoration:none}
    	A:visited {color:"blue";text-decoration:none}
    	A:hover {color:"red";text-decoration:}
    -->
    </STYLE>
    <%
    Dim oConnection 'As ADODB.Connection
    Dim oCmd 'As ADODB.Command
    Dim oField 'As ADODB.Field
    Dim oRootDSE 'As IADs
    Dim strNamingContext 'As String
    Dim strADOQuery 'As String
    Dim strAttributes 'As String
    Dim strFilter 'As String
    
    Set oConnection = server.CreateObject("ADODB.Connection")
    Set oCmd = server.CreateObject("ADODB.Command")
    Set oRecordSet = server.CreateObject("ADODB.Recordset")
    
    strAttributes="samaccountname,name,manager,company,description"
    
    Set oRootDSE = GetObject("LDAP://RootDSE")
    strNamingContext = oRootDSE.Get("defaultNamingContext")
    Set oRootDSE = Nothing
    
    strFilter="samaccountname="
    
    oConnection.Provider = "ADsDSOObject"
    oConnection.Open "ADs Provider"
    Set oCmd.ActiveConnection = oConnection
    strADOQuery = "<LDAP://" & strNamingContext & ">;(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2)" + strFilter + "*);" + strAttributes + ";subtree"
    
    oCmd.CommandText = strADOQuery
    ocmd.Properties("Sort on")="samaccountname"
    ocmd.Properties("Page Size") = 6000
    
    oRecordSet.CursorLocation = 3
    oRecordSet.Open oCmd, , 0, 1
    response.write "Record count : " & cstr(oRecordSet.RecordCount)
    %>
    <table  border="1" cellspacing="1" width="100%">
    <tr><td colspan="7" >
      <p align="center"><b>Active Directory Users</b></tr>
    <tr>
      <td width="8%" align="center">Login</td>
      <td width="10%" align="center">Name</td>
      <td width="10%" align="center">Manager</td>
      <td width="8%" align="center">Company</td>
      <td width="30%" align="center">Description</td>
    </tr>
    <%
    while not oRecordset.eof
    %>
    <tr>
    <td width="8%">
    <%
    response.write(oRecordset("samaccountname"))
    %>&nbsp;</td>
    <td width="10%"><%=oRecordset("name")%>&nbsp;</td>
    <td width="10%">
    <%
    if not isnull(oRecordset("manager")) then
    svmgr=split(oRecordset("manager"),",",-1,1)
    svm=split(svmgr(0),"=",-1,1)
    response.write(svm(1))
    end if
    
    %>
     &nbsp;</td>
    <td width="8%">
    <%
    if not isnull(oRecordset("company")) then
    response.write(oRecordset("company"))
    end if
    %>
     &nbsp;</td>
    <td width="30%">
    <%
    If Not IsNull(oRecordSet.Fields("description").Value) Then
            For Each strdesc in oRecordSet.Fields("description").Value
                Response.Write strdesc
            Next
    End If
    %>
    &nbsp;
    </td>
    </tr>
    <%
    oRecordset.movenext
    wend
    %>
    </table>

    Comment

    Working...
    X