Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Integrate VB with Windows
Message
From
21/01/2004 19:30:45
 
 
To
17/01/2004 04:07:03
General information
Forum:
Visual Basic
Category:
Windows API functions
Miscellaneous
Thread ID:
00867761
Message ID:
00869316
Views:
22
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.
Previous
Reply
Map
View

Click here to load this message in the networking platform