Created
April 17, 2013 14:12
-
-
Save trevordevore/5404613 to your computer and use it in GitHub Desktop.
Getting user info from an Active Directory server using VBScript and LiveCode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
result = "" | |
theDomain = "[[Domain]]" 'domain with no trailing / | |
theQuery = "[[Query]]" 'query such as ou=Users,dc=... | |
theUser = "[[Username]]" | |
thePassword = "[[Password]]" | |
On Error resume next | |
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D | |
LDAPString = "LDAP://" | |
if not IsEmpty(theDomain) Then | |
LDAPString = LDAPString & theDomain & "/" | |
End If | |
LDAPString = LDAPString & "[[UserKey]]=" & theUser | |
If not IsEmpty(theQuery) Then | |
LDAPString = LDAPString & "," & theQuery | |
End If | |
Dim LDAP, lUser | |
Set LDAP = GetObject("LDAP:") | |
Set lUser = LDAP.OpenDSObject(LDAPString, theUser, thePassword, 0) | |
If Err.Number <> 0 Then | |
result = "error," & Err.Number ' default value | |
' http://www.selfadsi.org/errorcodes.htm | |
Select Case Err.Number | |
Case -2147463168 | |
result = "error,incorrect LDAP path" | |
Case -2147023570 | |
result = "error,invalid login credentials" | |
Case -2147463160 | |
result = "error,bad parameter" | |
Case -2147217911 | |
result = "error,permission denied" | |
Case -2147024891 | |
result = "error,insufficient rights" | |
Case -2147023541 | |
result = "error,domain does not exist" | |
Case -2147016671 | |
result = "error,protocol error" | |
Case -2147016656 | |
result = "error,no such object" | |
Case -2147016646 | |
result = "error,LDAP server is unavailable" | |
End Select | |
End If | |
if Err.Number = 0 Then | |
' Look for display name | |
If IsObject(lUser) Then | |
If lUser.Class = "user" or lUser.Class = "userProxy" Then | |
result = lUser.displayName | |
' Get groups use is member of | |
' Tab delimited on line 2 | |
lUserGroups = lUser.GetEx("memberOf") | |
'If IsObject(lUserGroups) Then | |
If Err.Number <> E_ADS_PROPERTY_NOT_FOUND Then | |
result = result & vblf | |
For Each objGroup in lUserGroups | |
result = result & objGroup & vbTab | |
Next | |
End If | |
End If | |
End If | |
End If |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put the VBScript into a variable and then execute as follows: | |
do theScript as "vbscript" | |
if the result begins with "error," then put item 2 to -1 of the result into theError | |
else | |
put the result into theADUserInfo ## last name, first name & cr & group & tab & group ... | |
end if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment