Break ON
; WHOSON.KIX: Display user account(s) logged on to a machine ; ; Author: Richard Howarth <rhowarth@*obscured*> ; ; Description: ; Show who's logged on to a machine ; ; Command line parameters: ; $HOST Computer to view, default is this computer.
$=SetOption("Explicit","ON") $=SetOption("WrapAtEOL","ON") $=SetOption("ASCII","ON")
Dim $oWMIService Dim $oProcess,$colProcess Dim $sProcessUser, $sProcessDomain
If Not IsDeclared($Host) Global $Host EndIf
If $Host="" $Host=@WKSTA EndIf
$oWMIService = GetObject("winmgmts:\\"+$Host+"\root\cimv2") If @ERROR "Cannot access WMI sevrice, error is " @ERROR ": " @SERROR ? Exit @ERROR EndIf $colProcess=$oWMIService.ExecQuery('Select * from Win32_Process where Name="explorer.exe"',,48) If @ERROR "Cannot access WMI sevrice, error is " @ERROR ": " @SERROR ? Exit @ERROR EndIf For Each $oProcess In $colProcess $sProcessDomain = $oProcess.ExecMethod_("GetOwner").Domain $sProcessUser = $oProcess.ExecMethod_("GetOwner").User $sProcessUser=$sProcessDomain+"\"+$sProcessUser If $sProcessUser="\" $sProcessUser="[unknown]" EndIf "User logged on to "+$HOST+": "+$sProcessUser+@CRLF Next
Exit 0
|