Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Integrate VB with Windows
Message
 
 
À
17/01/2004 04:07:03
Information générale
Forum:
Visual Basic
Catégorie:
Fonctions API de Windows
Divers
Thread ID:
00867761
Message ID:
00869316
Vues:
21
I've used the following tip I got somewhere:

First, declare the function like this:
Private Declare Function GetUserName Lib "advapi32.dll" _
    Alias "GetUserNameA" (ByVal lpBuffer As String, nSize _
    As Long) As Long
Then, you can use above function in a generic function like this:
Public Function RetrieveUserName() As String
    
    ' A const to specify the max length of the user name.
    Const MaxLen = 50
    
    ' Dim some variables to store the info.
    
    ' A string variable to hold the user name. This variable
    ' must be buffered in order for the function to work.
    Dim strName As String
    
    ' Used to contain the length of the name retrieved.
    Dim lngRetVal As Long
    
    ' Buffer the string with spaces.
    strName = Space$(MaxLen)
    
    ' Get the user name and assign it to strName;
    ' lngRetVal will hold the length of the user name.
    lngRetVal = GetUserName(strName, MaxLen)
    
    ' Now we must trim the remaining buffering spaces.
    strName = Trim$(strName)
    
    ' Because GetUserName returns a value with a trailing
    ' null termination character, we must remove that
    ' character.
    strName = Left$(strName, Len(strName) - 1)
    
    RetrieveUserName = strName
    
End Function
HTH.

>Hi Everybody,
>
>I have a VB6 application, which needs to use the windows login.
>
>Can anyone help me?. Thanks in advance.
It's "my" world. You're just living in it.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform