Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Sub Command1_Click()
MsgBox Environ("computername")
MsgBox Environ("UserName")
MsgBox user_name
End Sub
Private Function user_name() As String
Dim str As String
Dim res As Long
str = String(1024, 0)
res = GetUserName(str, 1024)
If res <> 0 Then
user_name = Mid(str, 1, InStr(1, str, Chr(0)) - 1)
Else
user_name = ""
End If
End Function