Kod:
Option Explicit
Private S1 As String
Private Declare Function GetUser Lib "mpr.dll" Alias "WNetGetUserA" (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function FindUserName() As String
S1 = Space(512)
GetUserName S1, Len(S1)
FindUserName = Trim$(S1)
End Function
Public Function FindNetUserName() As String
S1 = Space(512)
GetUser vbNullString, S1, Len(S1)
FindNetUserName = Trim$(S1)
End Function
Public Function FindComputerName() As String
S1 = Space(512)
GetComputerName S1, Len(S1)
FindComputerName = Trim$(S1)
End Function
Private Sub Form_Load()
Dim ComputerName, ComputerUser
ComputerUser = FindNetUserName
Text1.Text = ComputerUser
Text2.Text = FindComputerName
End Sub