И API-версия:
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Declare Function LookupAccountName Lib "advapi32.dll" Alias "LookupAccountNameA" (lpSystemName As String, ByVal lpAccountName As String, sid As Any, cbSid As Long, ByVal ReferencedDomainName As String, cbReferencedDomainName As Long, peUse As Long) As Long
Private Sub Form_Load()
Dim sDomainName As String * 255
Dim lDomainNameLength As Long
Dim sUserName as String
Dim bUserSid(255) As Byte
Dim lSIDType As Long
Rem Create a buffer
sUserName = String(100, Chr$(0))
Rem Get the username
GetUserName sUserName, 100
Rem strip the rest of the buffer
sUserName = Left$(sUserName, InStr(sUserName, Chr$(0)) - 1)
rem Show the temppath and the username
MsgBox "Hello " + strUserName
lResult = LookupAccountName(vbNullString, sUserName, bUserSid(0), 255, sDomainName, lDomainNameLength, _
lSIDType)
if lResult <>0 then
msgbox sDomainName
end if
end sub