CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 1999
    Posts
    60

    How can I find Current User in VB? Which key in registry tells?

    I tried to find it in the registry but always
    and all the time, I got:
    default user

    It gives right all the time but when the policy
    is set in NT for default user, then the problem
    occurs.

    Is there any other way or key to find out??

    A problem stays like a challenge till
    I find the solution to it.

  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: How can I find Current User in VB? Which key in registry tells?

    better use the GetUserName API.


  3. #3
    Join Date
    May 1999
    Posts
    3,332

    Re: How can I find Current User in VB? Which key in registry tells?

    sample

    private Declare Function GetUserNameA Lib "advapi32.dll" (byval strUser as string, byref lLen as Long) as Boolean

    public Function CurrentUser() as string
    Dim strBuffer as string * 255
    Dim lLen as Long
    lLen = len(strBuffer)
    If GetUserNameA(strBuffer, lLen) then
    CurrentUser = UCase$(Left$(strBuffer, lLen - 1))
    else
    CurrentUser = ""
    End If
    End Function

    usage:
    msgbox "Current user: " & CurrentUser()






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