how to get the full user name?

15,142

Solution 1

sys(0) returns both machine name and user something like

lcMachineUser = sys(0)
lcMachine = LEFT( lcMachineUser, AT( "#", lcMachineUser) -1 )
lcUserName = substr( lcMachineUser, AT( "#", lcMachineUser) +1 )

Solution 2

Alright, it seems like ths stuff is pretty old...and it's true ! ;) i've found a solution however, this can help someone, somewhere, someday :)

loScript = Createobject("MSScriptcontrol.scriptcontrol.1")
loScript.Language = "VBScript"

TESTVBS = [Set objSysInfo = CreateObject("ADSystemInfo")] + chr(13)+chr(10)+;
          [strUser = objSysInfo.UserName] + chr(13)+chr(10)+;
          [Set objUser = GetObject("LDAP://" & strUser)] + chr(13)+chr(10)+;
          [strFullName = objUser.Get("displayName")] + chr(13)+chr(10)
          *[MsgBox strFullName]

loScript.executestatement(TESTVBS)

this is how you execute VBS from Foxpro code...two technologies that are not technologies anymore :)

Solution 3

This will get the user's name from the environmental variables.

username = GETENV("UserName")
Share:
15,142

Related videos on Youtube

user1327073
Author by

user1327073

Updated on June 04, 2022

Comments

  • user1327073
    user1327073 over 1 year

    I have the following code in VBS that works perfectly. it queries AD to get the user full name :

    Set objSysInfo = CreateObject("ADSystemInfo")
    strUser = objSysInfo.UserName
    Set objUser = GetObject("LDAP://" & strUser)
    strFullName = objUser.Get("displayName")
    MsgBox strFullName
    

    i would like to do the same thin but in Foxpro 7. anybody has experience with VFP 7 or 9 ?