user1327073
user1327073

Reputation: 1084

how to get the full user name?

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 ?

Upvotes: 3

Views: 16592

Answers (4)

gavroche
gavroche

Reputation: 249

I 'm using this function:

FUNCTION Get_User()
  LOCAL cUsrBuf, nUsrLen, cUserName
  cUsrBuf = SPACE(20)
  nUsrLen = 20
  DECLARE GetUserName IN advapi32 AS GetUserName STRING @cusrbuf, LONG @nusrlen
  =GetUserName(@cusrbuf, @nusrlen)
  cUserName = LEFT(ALLTRIM(cusrbuf), LEN(ALLTRIM(cusrbuf)) - 1)
 RETURN cUserName
ENDFUNC

I would avoid using SYS(0) because: SYS(0) returns 1 when using Visual FoxPro in a stand-alone environment

Only when the machine is connected to a network, SYS(0) returns the machine name, a space, a number sign (#) followed by another space, and then the id of the current user (or the security context in which Visual FoxPro is running).

Upvotes: 0

Jerry
Jerry

Reputation: 6577

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

username = GETENV("UserName")

Upvotes: 2

DRapp
DRapp

Reputation: 48169

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 )

Upvotes: 3

user1327073
user1327073

Reputation: 1084

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 :)

Upvotes: 2

Related Questions