Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Getting a logged on usre name in an NT workstaion


Message #1 by "Rajendra Dev Adhikari" <rdadhikari@h...> on Sat, 20 Jan 2001 17:26:50 +0530
Here's an API call will do it:

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

Private Sub Form_DblClick()
Dim sUserName As String
Dim lSize As Long

lSize = 20

sUserName = Space(20)

Call GetUserName(sUserName, lSize)

'trim off the trailing spaces
sUserName = Trim(sUserName)

'trim off the trailing null
sUserName = Left(sUserName, Len(sUserName) - 1)

MsgBox sUserName

End Sub

the sUserName must be initialized before sending it into the function.  lSize, on
the way in indicates the length of the buffer, but on the way out, indicates the
actual length of the string returned.  sUserName's value is NULL terminated, so
after removing the trainling blanks, then remove the trailing NULL value.

hope this helps,

john

  Return to Index