Retrouver le UserName NT.

 

Le plus simple est d'utiliser l'API qui est à généreusement mise à notre disposition : GetUserName

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


Private Sub Command1_Click()

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)

Label1.Caption = NTDomainUserName
' Ne pas oublier le label Label1dans la form...

End Sub