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

Get User Name not Login ID

Status
Not open for further replies.

jw45

Programmer
May 27, 2005
56
US
I have searched and reasd many posts here and founf several ways to get the userid and computer name,
Like:
Environ("username")
Environ("computername")


However, I can not find anything on how to find the user's name. ie. like the name used on the top of the start menu in XP.

Is it possible to get these also?

Thanks,
JW
 

Code:
for i = 0 to 500
 debug.print environ(i).name ": " & environ(i) 
next i
take a peek

Randall Vollen
National City Bank Corp.
 
Actually, the environ() function returns a string and not an object, so you can't actually get a .Name property. It's also 1-based, and limited to 255 at least in WinXP.

So the following does what hwkranger wants:

dim i as integer
for i = 1 to 500
debug.print environ(i)
next i

You can use the text to the left of the "=" sign as a feed to the environ() function rather than a number...


...but, none of those answer jw45's question. I don't see the information he is looking for in the environ settings.
 
Here is a way to get the users name.

In the declartion section of a standard module. Add.

Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal _
lpBuffer As String, nSize As Long) As Long


Add a function in the standard module.

Function get_username() As String
Dim lpBuff As String * 25
Dim ret As Long
Dim Username As String

ret = GetUserName(lpBuff, 25)
Username = VBA.Left(lpBuff, VBA.InStr(lpBuff, VBA.Chr(0)) - 1)

get_username = VBA.UCase(Username)
Debug.Print "user name = "; get_username

End Function
 
Thanks rubbernilly, although that did not get me what I was looking for, it gave me some additional things I did not know where available.

cmmrfrds... that returns the same thing (on my computer at least) that environ("username") returns. It is what I call the LoginID and not the persons name like "John Doe".

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top