Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get NT User Name using VB

Status
Not open for further replies.

HomerJS

Programmer
Jun 25, 2001
86
US
How can I get a person's NT full name (Homer Simpson), not just their user name (HomerS), using VB?

Any extra help on other NT info I can get would be a bonus.

Thanks...

 
I don't have NT but this works in Win ME
Code:
Private Declare Function GetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, _
    nSize As Long) As Long

Private Declare Function WNetVerifyPassword Lib "mpr.dll" Alias _
    "WNetVerifyPasswordA" (ByVal lpszPassword As String, _
    ByRef pfMatch As Long) As Long

Private Function GetWindowsLoginUserID() As String
    Dim rtn As Long
    Dim sBuffer As String
    Dim lSize As Long
    sBuffer = String$(260, Chr$(0))
    lSize = Len(sBuffer)
    rtn = GetUserName(sBuffer, lSize)
    If rtn Then
        sBuffer = Left$(sBuffer, lSize)
        If InStr(sBuffer, Chr$(0)) Then
            sBuffer = _
            Left$(sBuffer, InStr(sBuffer, Chr$(0)) - 1)
        End If
        GetWindowsLoginUserID = sBuffer
    Else
        GetWindowsLoginUserID = ""
    End If
End Function
 
Thanks for your help. It does work on NT.

But the information I'm really looking for is a person's FULL name (Homer Simpson), not just their user name (HomerS).
 
I haven't really converted C code to VB code. It seems like the code on the support page isn't exactly easy code to convert either.
 
John,

I am looking to do the same thing, and include security priveledges. not to side step the original subject I have a novice question about the code you wrote.

will your functions work on project activation or will I have to call the function "GetWindowsLoginUserID()" somewhere. also I am not understanding why you declared the dll's???

thanks for the help
Christina
 
That kind of clean-up I can handle. It did take me a little bit to figure out to put the name of our PDC. (reading the comments in the code helps :) )

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top