Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Retrieving user's loginname
Message
 
To
09/07/1999 14:19:22
General information
Forum:
Visual Basic
Category:
Other
Miscellaneous
Thread ID:
00239556
Message ID:
00239794
Views:
16
>In Visual Fox, the function sys(0) will return the user's logon name. Is there a similar function available in Visual Basic? I hope I don't have to go into Win API just to get the user's name.

Yes, you need to go to the API to retrieve it, but you don't need as much code as Penmetsa wrote.

Try this simple code.

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

Private Sub Command1_Click()
Dim lngSize As Long
Dim strBuffer As String

strBuffer = Space$(255)
lngSize = Len(strBuffer)
Call GetUserName(strBuffer, lngSize)
If lngSize > 0 Then
MsgBox Left$(strBuffer, lngSize)
Else
MsgBox "Unknown user"
End If
End Sub
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Previous
Reply
Map
View

Click here to load this message in the networking platform