CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: NT User

  1. #1
    Join Date
    Nov 1999
    Location
    France
    Posts
    29

    NT User

    Hi everybody

    How can I get the Windows NT Login of the current user in my app?

    Fzz


  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: NT User

    I always found the GetUserName() API call worked fine for me (there are other calls you can use).

    Paste the following code into a form :


    option Explicit

    private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (byval lpBuffer as string, nSize as Long) as Long

    private Sub Form_Load()
    Dim sBuffer as string
    Dim lRet as Long
    Dim sUserName as string

    '
    ' Fill the buffer with char(0)
    '
    sBuffer = string$(255, vbNullChar)

    lRet = GetUserName(sBuffer, 255)
    If lRet = 1 then
    sUserName = Left$(sBuffer, InStr(sBuffer, vbNullChar) - 1)
    else
    sUserName = "Unknown - error"
    End If
    MsgBox sUserName

    End Sub






    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured