Link to home
Start Free TrialLog in
Avatar of aluiken
aluiken

asked on

Network login name

Hi there,

Is there a way to find out the currently logged in user name for microsoft networking (so NOT the windows password?)

Cheers
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jetforce
jetforce

If I understand right, you just want to get the username of who is logged in? if so try this API
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

and then just call it eg:-
GetUserName strUser, 10

lpbuffer is the string that you want the username to go into and nSize is the length of the string.

hope this helps

Jetforce
I was too late, just ignore my post
By the way, here's another way:

Private Declare Function WNetGetUserA Lib "mpr" (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long
Function GetUserID() As String
    Dim lName As String * 255
    lName = Space(255)
    Call WNetGetUserA(vbNullString, lName, 255&)
    GetUserID = Left$(lName, InStr(lName, vbNullChar) - 1)
End Function

Private Sub Command1_Click()
    MsgBox GetUserID
End Sub



Cheers!®©
Avatar of aluiken

ASKER

Very good, thx
Thanks for the points! Glad I could help!


Cheers!®©