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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AD Common Name

Status
Not open for further replies.

efpav

IS-IT--Management
Feb 17, 2004
24
US
If I use ADSystemInfo, I can pull out the user's Common Name from the Active Directoy, but comes with it is also OU and Domain Names. Is it possible to truncate this or only pull out the user's alias?

Thanks...
 
Please post code as to what you are doing here. Here is a solution that will get the common names of all of the objects in AD that are of type 'user'. I don't know if this is what you're really after or not. You were very vague in your post.

You will need a reference to ActiveX Data Objects.

Code:
    Dim con As ADODB.Connection
    Dim rs As ADODB.Recordset
    
    Set con = New ADODB.Connection
    
    con.ConnectionString = "ADSI Flag=""-2147483648"";Provider=ADsDSOObject;Encrypt Password=False;Mode=Read;Bind Flags=0"
    
    con.Open
    
    Set rs = con.Execute("SELECT cn FROM 'LDAP://DC=DOMAIN,DC=COM' WHERE ObjectClass='user'")
    
    Do While Not rs.EOF
        Debug.Print rs("cn")
        rs.MoveNext
    Loop
    
    rs.Close
    Set rs = Nothing
    con.Close
    Set con = Nothing
 
Oh, if it is the actual username that you're looking for replace cn in the example above with samAccountName or userPrincipalName.

userPrincipalName is the Windows 2000 version. It will be in username@domain.com format.
 
This is for a logon script that launches Outlook Express. I want the user's name to appear on the titlebar, but this script shows the users logon name, which is firstname.lastname.

stTitlebar = "Welcome" & " " & objNetwork.Username
MsgBox "Please check for new e-mail messages", vbExclamation, stTitlebar
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "msimn.exe
 
If you want the users first and last names and the Username *always* is first.last then you can use

Code:
Dim FirstName
Dim LastName

FirstName = Split(objNetwork.Username, ".")(0)
LastName = Split(objNetwork.Username, ".")(1)

stTitlebar = "Welcome " & FirstName & " " & LastName
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top