Getting User's NT Login programatically 
Author Message
 Getting User's NT Login programatically

Using VB and/or VBA, how would one get a user's NT login?  I'm sure i've
seen it done before - I must be searching on the wrong keywords.
Thanks,
PB


Sat, 02 Nov 2002 03:00:00 GMT  
 Getting User's NT Login programatically

Quote:

>Using VB and/or VBA, how would one get a user's NT login?  I'm sure i've
>seen it done before - I must be searching on the wrong keywords.

Paste this declaration into the General Declarations section of a form:

Private Declare Function WNetGetUser Lib "mpr.dll" Alias _
    "WNetGetUserA" (ByVal lpName As String, _
    ByVal lpUserName As String, lpnLength As Long) As Long

Use code like this to retrieve the user name:

    Dim lSize As Long, lResult As Long, sUserName As String
    lSize = 40
    sUserName = String(lSize, vbNullChar)
    lResult = WNetGetUser(vbNullString, sUserName, lSize)
    sUserName = Left(sUserName, InStr(sUserName, Chr$(0)) - 1)

Lee Weiner
weiner AT fuse DOT net
http://home.fuse.net/lweiner



Sun, 03 Nov 2002 03:00:00 GMT  
 Getting User's NT Login programatically
On Tue, 16 May 2000 17:17:34 -0400, "Paul Brady"

Quote:

>Using VB and/or VBA, how would one get a user's NT login?  I'm sure i've
>seen it done before - I must be searching on the wrong keywords.
>Thanks,
>PB

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

Public Function SYSGetUserName() As String

    Dim Username As String
    Dim BufSize As Long
    Dim RetCode As Long
    Dim NullCharPos As Long

    Username = Space(80)
    BufSize = Len(Username)

    '---call WINAPI
    RetCode = GetUserName(Username, BufSize)

    '---search for the end of the string
    NullCharPos = InStr(Username, Chr(0))
    If NullCharPos > 0 Then
        Username = Left(Username, NullCharPos - 1)
    Else
        Username = ""
    End If

    SYSGetUserName = Username

End Function



Mon, 04 Nov 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Need Help Getting User's Group From Login Account on NT

2. Getting NT Users LOGIN NAME?

3. Getting Netware Login User Id under NT

4. Getting NT User Login Name

5. How do I programatically modify a User's NT Group membership in VB

6. How to capture user's NT login?

7. NH: Need to have user login with their NT login

8. How Do I get the users login programatically?

9. Getting the NT user's primary group.

10. Login failed for user 'XYZ1492\IUSR_XYZ1492'

11. VB can't run non-Microsoft OCX when user don't login as Adminsitrator

12. login failed for user '(null)'

 

 
Powered by phpBB® Forum Software