Click to See Complete Forum and Search --> : Picking up currently logged in user name with VBA


wolfstar777
September 4th, 2001, 09:13 PM
I need a way to pick up the name the currently logged in user. The OS is windows NT 4 and the code will form part of an Excel module. It doesn't matter where the name comes from, if someone has a way of extracting the information from the registry I can adapt the code to suite my system. Thanks in advance.

Cakkie
September 5th, 2001, 01:31 AM
This will do the job

Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (byval
lpBuffer as string, nSize as Long) as Long

Function GetUser() as string

Dim lpUserID as string
Dim nBuffer as Long
Dim Ret as Long
lpUserID = string(25, 0)
nBuffer = 25
Ret = GetUserName(lpUserID, nBuffer)

If Ret <> 0 then
GetUser = lpUserID
End If

End Function




Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

Martin Smith
September 5th, 2001, 03:33 AM
Or

Environ("UserName")