' Pandora FMS Agent Inventory Plugin for Microsoft Windows (All platfforms) ' (c) 2015 Borja Sanchez ' This plugin extends agent inventory feature. Only enterprise version ' -------------------------------------------------------------------------- on error resume next ' Lista todos los usuarios del equipo que han iniciado procesos dim loggedUsers(),i i=0 Sub insertIfNotExists(sDomain,sUser) For Each lUser in loggedUsers If StrComp(sDomain & "\" & sUser, lUser) = 0 Then Exit Sub End If Next redim preserve loggedUsers(i) i=i+1 loggedUsers (i-1)=sDomain & "\" & sUser End Sub Function CheckRealUser(sHost, sUser, sDomain) Dim oWMI,realUsers Set oWmi = GetObject("winmgmts:{impersonationLevel=impersonate,(debug)}!\\" _ & sHost & "\root\cimv2") Set realUsers = oWmi.ExecQuery("SELECT * FROM Win32_UserAccount WHERE Domain='" & sDomain & "' OR Name='" & sUser & "'") If (realUsers.count=0) Then CheckRealUser = False Else CheckRealUser = True End If End Function Function ConsoleUser(sHost) Dim oWMI, colProc, oProcess, strUser, strDomain Set oWmi = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate,(debug)}!\\" _ & sHost & "\root\cimv2") Set colProc = oWmi.ExecQuery("Select sessionID from Win32_Process") ConsoleUser = "" For Each oProcess In colProc lRet = oProcess.getOwner(strOwner, strDomain) If (lRet = 0) AND (CheckRealUser(sHost,strOwner,strDomain)) Then insertIfNotExists strDomain,strOwner ConsoleUser = sUser End If Next End Function ' MAIN sUser = ConsoleUser(".") ' use "." for local computer Wscript.StdOut.WriteLine "" Wscript.StdOut.WriteLine "" Wscript.StdOut.WriteLine "Users" Wscript.StdOut.WriteLine "" Wscript.StdOut.WriteLine "" For Each usuario in loggedUsers Wscript.StdOut.WriteLine "" next Wscript.StdOut.WriteLine "" Wscript.StdOut.WriteLine "" Wscript.StdOut.WriteLine ""