Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Retrieving user's loginname
Message
 
À
09/07/1999 14:19:22
Information générale
Forum:
Visual Basic
Catégorie:
Autre
Divers
Thread ID:
00239556
Message ID:
00239794
Vues:
20
>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform