Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Object data from LDAP

Status
Not open for further replies.

Deception

IS-IT--Management
May 2, 2002
6
US
I started off trying to get the following VBS code working in Extra Basic.

Code:
Dim strGreeting

Set Shell = WScript.CreateObject("WScript.Shell")
Set oInfo = WScript.createObject("ADSystemInfo")
Set LDAPUsr = GetObject("LDAP://" & oInfo.UserName)

strGreeting = "Hello " & LDAPUsr.FirstName & " " & LDAPUsr.LastName
shell.popup strGreeting

Using the Object explorer I came across "Active DS Type Library" and was hoping to use it to grab the user's First and Last name. However, I'm extremely rusty on my coding and not able to get it working. I'm only able to grab UserName (ex: CN=Jeff Smith,OU=Sales,DC=Fabrikam,DC=Com). FirstName and LastName are within IADsUser, I just can't figure out how to grab the info.

Code:
Sub Main
    Dim sysInfo as Object
    Dim user as String

    Set sysInfo = CreateObject("ADSystemInfo")
    user = sysInfo.UserName
    
    msgbox user
End Sub

Any assistance you can provide on a working solution would be greatly appreciated.
 
I ended up parsing the info the old fashion way. However, I'm still interested to know whether the VBS method can be used in Extra Basic somehow because it would just be cool and much cleaner.

Code:
Sub Main
    Dim sysInfo as Object
    Dim position as Integer, position2 as Integer, length as Integer
    Dim user as String, LastName as String, FirstName as String

    Set sysInfo = CreateObject("ADSystemInfo")
    user$ = sysInfo.UserName
    
    'This assumes sysInfo.UserName begins as follows:
    'CN=LastName\, FirstName  USERID,OU=Sales,OU=Accounts,DC=Fabrikam,DC=com
    
    'Obtain LastName
    position% = InStr(user$,"\")
    length% = (position% - 3) - 1
    LastName$ = Mid$(user$, 4, length%)
    
    'Obtain FirstName
    position% = position% + 3
    position2% = InStr(position%, user$, " ")
    length% = (position2% - position%)
    FirstName$ = Mid$(user$, position%, length%)
   
    msgbox "Hello " + FirstName$ + " " + LastName$
End Sub
 
Deception,
Here's an example for the Active DS Type Library.

This should return the iADsUser object. You will just need to supply the Domain and User which you should be able to get from [tt]ADSystemInfo[/tt] or [tt]ENVIRON$()[/tt].
Code:
...
strOutput = "WinNT://[i]Domain[/i]/[i]User[/i],User"
Set objIADsUser = GetObject(strOutput)
...

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top