Click to See Complete Forum and Search --> : How can I find Current User in VB? Which key in registry tells?


Naveed Anis
February 17th, 2000, 02:45 AM
I tried to find it in the registry but always
and all the time, I got:
default user

It gives right all the time but when the policy
is set in NT for default user, then the problem
occurs.

Is there any other way or key to find out??

A problem stays like a challenge till
I find the solution to it.

Lothar Haensler
February 17th, 2000, 02:57 AM
better use the GetUserName API.

Lothar Haensler
February 17th, 2000, 02:58 AM
sample

private Declare Function GetUserNameA Lib "advapi32.dll" (byval strUser as string, byref lLen as Long) as Boolean

public Function CurrentUser() as string
Dim strBuffer as string * 255
Dim lLen as Long
lLen = len(strBuffer)
If GetUserNameA(strBuffer, lLen) then
CurrentUser = UCase$(Left$(strBuffer, lLen - 1))
else
CurrentUser = ""
End If
End Function

usage:
msgbox "Current user: " & CurrentUser()