Option Explicit
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
Function Usuario() As String
Dim Nombre As String * 255, Respuesta As Long, Longitud As Long, Res As Long
'Crea Buffer
Nombre = ""
Longitud = Len(Nombre)
Res = GetUserName(Nombre, Longitud)
If Res And Longitud > 0 Then
Usuario = Left$(Nombre, Longitud)
Else
Usuario = "No encontrado"
End If
End Function
Function Ordenador() As String
Dim Nombre As String * 255, Respuesta As Long, Longitud As Long, Res As Long
'Crea Buffer
Nombre = ""
Longitud = Len(Nombre)
Res = GetComputerName(Nombre, Longitud)
If Res And Longitud > 0 Then
Ordenador = Left$(Nombre, Longitud)
Else
Ordenador = "No encontrado"
End If
End Function
Private Sub Form_Load()
Tx_Datos(0).Text = Usuario
Tx_Datos(1).Text = Ordenador
End Sub