Sign in to follow this  
Followers 0
rogerd2u

How To Get A Users Full Name

13 posts in this topic

#1 ·  Posted (edited)

Do any of you know how to get a users "full name"? So, for instance, Bob Smith's login name is "bsmith" I would like to display a splash screen saying something to the effect of, "Hello, Bob Smith!" As you know, the Macro, @UserName, only gives the login name. There is a "Full Name" description for all our user accounts, but I can't find a way to pull from that field.

We are in a Windows 2003 domain.

If anyone has been successful in getting this to work, would you please post your code?

Thanks in advance! :)

Roger

Edited by rogerd2u

Roger O."When people show you who they are, believe them.” --Mark Twain

Share this post


Link to post
Share on other sites



Beta required:

$oMyError = ObjEvent("AutoIt.Error", "ComError")
$UserObj = ObjGet("WinNT://" & @LogonDomain & "/" & @UserName)
If @error Then
    MsgBox(0, 'username', 'Error connecting to domain')
Else
    MsgBox(0, 'username', $UserObj.FullName)
EndIf
$UserObj = ""
$oMyError = ObjEvent("AutoIt.Error", "")
;COM Error function
Func ComError()
    If IsObj($oMyError) Then
        $HexNumber = Hex($oMyError.number, 8)
        SetError($HexNumber)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc  ;==>ComError

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Awesome! Thanks so much, JdeB! That is exactly what I needed.

Roger


Roger O."When people show you who they are, believe them.” --Mark Twain

Share this post


Link to post
Share on other sites

Now, can you tell me how I could use this script so that I could just get the users First name? :)


Roger O."When people show you who they are, believe them.” --Mark Twain

Share this post


Link to post
Share on other sites

Now, can you tell me how I could use this script so that I could just get the users First name? :)

you could do something like

$oMyError = ObjEvent("AutoIt.Error", "ComError")
$UserObj = ObjGet("WinNT://" & @LogonDomain & "/" & @UserName)
If @error Then
    MsgBox(0, 'username', 'Error connecting to domain')
Else
    $Name = StringSplit($UserObj.FullName, " ")
    MsgBox(0, 'username', "First Name: " & $Name[2] & @CRLF & "Last Name: " & $Name[1])
EndIf
$UserObj = ""
$oMyError = ObjEvent("AutoIt.Error", "")
;COM Error function
Func ComError()
    If IsObj($oMyError) Then
        $HexNumber = Hex($oMyError.number, 8)
        SetError($HexNumber)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc ;==>ComError

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Thanks, gafrost!


Roger O."When people show you who they are, believe them.” --Mark Twain

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Now, can you tell me how I could use this script so that I could just get the users First name? :)

If you want what is defined in the AD you can do it this way. This will give you access to lots of AD information...See here for details

Const $ADS_NAME_INITTYPE_GC = 3
Const $ADS_NAME_TYPE_NT4 = 3
Const $ADS_NAME_TYPE_1779 = 1
$oMyError = ObjEvent("AutoIt.Error", "ComError")
$objRootDSE = ObjGet("LDAP://RootDSE")
If @error Then
    MsgBox(0, 'username', 'Error connecting to domain')
Else
; DNS domain name.
    $objTrans = ObjCreate("NameTranslate")
    $objTrans.Init ($ADS_NAME_INITTYPE_GC, "")
    $objTrans.Set ($ADS_NAME_TYPE_1779, @LogonDomain)
    $objTrans.Set ($ADS_NAME_TYPE_NT4, @LogonDomain & "\" & @UserName)
    $strUserDN = $objTrans.Get ($ADS_NAME_TYPE_1779)
    $UserObj = ObjGet("LDAP://" & $strUserDN)
    If @error Then
        MsgBox(0, 'username', 'Error connecting to domain')
    Else
        MsgBox(0, 'username', $UserObj.FullName & "  Firstname:" & $UserObj.FirstName)
    EndIf
EndIf
$UserObj = ""
$oMyError = ObjEvent("AutoIt.Error", "")
;COM Error function
Func ComError()
    If IsObj($oMyError) Then
        $HexNumber = Hex($oMyError.number, 8)
        SetError($HexNumber)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc ;==>ComError
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

$Name = StringSplit($UserObj.FullName, " ")
    MsgBox(0, 'username', "First Name: " & $Name[2] & @CRLF & "Last Name: " & $Name[1])
The issue with this solution is when people have double lastnames and/or middle initials ......

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

The issue with this solution is when people have double lastnames and/or middle initials ......

thanks,

you might also want to add some string replacement for special chars in it

for example ours has location/company in the name

so....

$strUserDN = StringReplace($objTrans.Get ($ADS_NAME_TYPE_1779),"/","\/")

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

thanks,

you might also want to add some string replacement for special chars in it

for example ours has location/company in the name

so....

$strUserDN = StringReplace($objTrans.Get ($ADS_NAME_TYPE_1779),"/","\/")
I cannot test it now, but i thougth that this statement retrieved the fully qualified domainname which is needed to be able to use the LDAP com object. Are you saying it is not working the way I coded it and the slashes need to be prefixed with a backslash for the LDAP object retrieval to work ?

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I cannot test it now, but i thougth that this statement retrieved the fully qualified domainname which is needed to be able to use the LDAP com object. Are you saying it is not working the way I coded it and the slashes need to be prefixed with a backslash for the LDAP object retrieval to work ?

yep, was getting an error, took a few minutes to figure out the slash was the problem


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Hiho,

is there a way to see all possible infos about the user? More than just the FullName. (Ex.: SID)

$UserObj. ???

Haven't found something on microsoft.com. Only for WMI services...

greets an thx in advance

Sundance

OKAY i should better read the answers !! haven't seen the link from JdeB. :-) (but there's also no option for the SID...)

Finally i got it with WMI-Services.. :-))

Edited by Sundance

Share this post


Link to post
Share on other sites

#13 ·  Posted

Hiho,

is there a way to see all possible infos about the user? More than just the FullName. (Ex.: SID)

$UserObj. ???

Haven't found something on microsoft.com. Only for WMI services...

Finally i got it with WMI-Services.. :-))

Would you mind posting that?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0