Hope this is what you are looking for.
It returns the network user name
Public Function CStringToVBString(psCString As String) As String
' **********
' Purpose: Convert a C string to a VB string
' Parameters: (Input Only)
' psCString - the C string to convert
' Returns: The converted VB string
' Notes:
' Returns everything to the left of the first Null character
' **********
Dim sReturn As String
Dim iNullCharPos As Integer
iNullCharPos = InStr(psCString, vbNullChar)
If iNullCharPos > 0 Then
' return everything left of the null
sReturn = Left(psCString, iNullCharPos - 1)
Else
' no null, return the original string
sReturn = psCString
End If
CStringToVBString = sReturn
End Function
Finally, here's the wrapper around Win32's WNetGetUser function:
Public Function WNetGetUser() As String
' **********
' Purpose: Retrieve the network user name
' Paramters: None
' Returns: The indicated name
' Notes:
' A zero-length string is returned if the function fails
' **********
Dim lpUserName As String
Dim lpnLength As Long
Dim lResult As Long
lpnLength = 256
lpUserName = Space(lpnLength)
lResult = w32_WNetGetUser(vbNullString, lpUserName, lpnLength)
If lResult = NO_ERROR Then
WNetGetUser = CStringToVBString(lpUserName)
Else
WNetGetUser = ""
End If
End Function