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

 

Public Function NTDomainUserName() As String

Dim strBuffer As String * 255

Dim lngBufferLength As Long

Dim lngRet As Long

Dim strTemp As String

 

lngBufferLength = 255

lngRet = GetUserName(strBuffer, lngBufferLength)

strTemp = UCase(Trim$(strBuffer))

NTDomainUserName = Left$(strTemp, Len(strTemp) - 1)

 

End Function