WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADSI LDAP CDO
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

ADSI COM Example - Get User Properties


;Get user properties

;Constants for the NameTranslate object.
ADS_NAME_INITTYPE_DOMAIN = 1
ADS_NAME_TYPE_NT4 = 3
ADS_NAME_TYPE_1179 = 1

; Specify NT name. You could also prompt for this, or pass
; the name as a parameter. Or, if you want the DN of the
; current user, you could retrieve this from Environment("USERNAME")
strNTName = Environment("USERNAME")

; Determine DNS domain name from RootDSE object.
objRootDSE = ObjectOpen("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

; Use the NameTranslate object to find the NetBIOS domain name from the
; DNS domain name.
objTrans = ObjectAccess("NameTranslate",@true)
objTrans.Init(ADS_NAME_TYPE_NT4, strDNSDomain)
objTrans.Set(ADS_NAME_TYPE_1179, strDNSDomain)
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
; Remove trailing backslash.
strNetBIOSDomain = StrSub(strNetBIOSDomain,1,StrLen(strNetBIOSDomain) - 1)

; Use the NameTranslate object to convert the NT user name to the
; Distinguished Name required for the LDAP provider.
objTrans.Init(ADS_NAME_INITTYPE_DOMAIN, strNetBIOSDomain)
objTrans.Set(ADS_NAME_TYPE_NT4, StrCat(strNetBIOSDomain , "\" , strNTName))
strUserDN = objTrans.Get(ADS_NAME_TYPE_1179)

; Bind to the user object in Active Directory with the LDAP provider.
objUser = Objectopen(StrCat("LDAP://" , strUserDN))

Message("Name: " , objUser.Name)
Message("userPrincipalName: " , objUser.userPrincipalName)
Message("samAccountName: " ,objUser.samAccountName)
Message("displayName: " , objUser.displayName)
Message("fullName: " , objUser.fullName)
Message("employeeID: " , objUser.employeeID)
Message("mail: " , objUser.mail)
Message("LastLogin: " , objUser.lastlogin)
Message("createTimeStamp" , objUser.createTimeStamp)
Message("Parent: " , objUser.Parent)
exit





Article ID:   W16086
File Created: 2005:04:05:12:23:56
Last Updated: 2005:04:05:12:23:56