views:

316

answers:

2

OK.. I am not really good at asking questions, but the title says it all. I got my script querying Active Directory to work when called from the command windows, but it won't work on my ASP page. Instead of echo("message") in the VBS file, I used Response.Redirect(message) in my ASP. So here's the code that is working fine in the CMD window, but not in IE. Anyway, I hope someone can help.

Option Explicit

Dim objRootDSE, strDNSDomain, objCommand, objConnection
Dim strQuery, strBase, strFilter, strAttributes
Dim objRecordSet, strAlias, strName, strSAM
Dim blnFlag

''// 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

''// Set AD query propeties
strBase = "<LDAP://10.10.10.10>"
strFilter = "(&(objectCategory=person)(objectClass=user)(cn="gossmari")"
strAttributes = "displayName,mailNickname,sAMAccountName"

''// AD query
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute

    Do Until objRecordSet.EOF
       strName = objRecordSet.Fields("displayName")
       strAlias = objRecordSet.Fields("mailNickname")
       strSAM = objRecordSet.Fields("sAMAccountName")
       objRecordSet.MoveNext
    Loop

''// Echo the requested information 
''// replaced by Response.Redirect("http://www.google.com/" & strName)
Wscript.Echo strSAM & " ; " & strAlias & " ;   " & strName

objConnection.Close

edit : The error I keep getting is : An error occurred on the server when processing the URL. Please contact the system administrator. If you are the system administrator please click here to find out more about this error.

My computer is running windows vista and I'm really starting to hate it

A: 

Actually giving us the Error message would help.

If you are running IE out the box you will not see it. Go to Tools, Internet Options, Advanced Tab and turn off "Show friendly HTTP Error Messages"

Generally accessing stuff like active directory will not work due to the security context that the default anonymous IIS user runs in, so if you switch to integrated security you might get further.

feihtthief
+1  A: 

What error is it returning?

One possible cause may be the credentials that the ASP page is executing under do not have permission to query Active Directory. If it's a default web page, it's probably running with anonymous authentication, which translates into [LOCALMACHINE]\IUSR_[LOCALMACHINE].

This would explain why it ran when run under your credentials, but not in the context of IIS.

Aaron Daniels