Palabras clave: WMI, usuario, remoto
Autor: Búho
Extraído de: La web del Búho
Objetivo
Obtener el usuario de un PC remoto mediante WMI.
Nota de Xavi: lo he depurado un poquito...
Option Compare Database
Option Explicit
Public Function WMI_INSTALADO() As Boolean
'http://www.microsoft.com/latam/technet/articulos/windows2k/wmixwdm/
'lo anterior si quieres saber qué significa WMI
Dim WMI As Object
On Error Resume Next
Set WMI = GetObject("winmgmts:")
WMI_INSTALADO = (Err.Number = 0)
End Function
Private Sub Form_Load()
If WMI_INSTALADO() Then
MsgBox "Su sistema posee WMI"
getWMI_Info
Else
MsgBox "Su sistema no posee WMI"
End If
End Sub
Private Sub getWMI_Info(strComputer as String)
Dim oAdapters As Object
Dim oAdapter As Object
' Control Errores
On Error GoTo Control_ERROR
Set oAdapters = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & StrComputer & "\Windows").ExecQuery( _
"SELECT * FROM Win32_ComputerSystem")
' Datos
For Each oAdapter In oAdapters
With oAdapter
MsgBox "Usuario: " & .UserName
End With
Next
On Error GoTo 0
Exit Sub
Control_ERROR:
MsgBox "Error: " & Err.Number & vbTab & Err.Description, vbCritical
Resume Next
End Sub