Rob, this is what I use.
Add this code to a module.
'Win32 API Functions - Used by the NTDomainUserName Procedure
Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function NTDomainUserName() As String
On Error GoTo ErrHandler
Dim sDllFound As String
sDllFound = Dir("C:\WINNT\System32\advapi32.dll")
If sDllFound <> vbNullString Then
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, InStr(strTemp, Chr$(0)) - 1)
Exit Function
End If
NTDomainUserName = vbNullString
ExitHandler:
Exit Function
ErrHandler:
MsgBox (Err.Number & vbCrLf & Err.Description)
Resume Next
End Function
Jerid
sDllFound = Dir("C:\WINNT\System32\advapi32.dll") If sDllFound <> vbNullString Then 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, InStr(strTemp, Chr$(0)) - 1) Exit Function End If NTDomainUserName = vbNullString
Cheers Jerid, works a treat.
Rob