How to get a list of users and the client IP addresses

Bonjour à tous



Voici un petit script récupéré ici : http://community.citrix.com/display/xa/How+to+get+a+list+of+users+and+the+client+IP+addresses+using+Citrix+MFCOM



Je pense qu’il pourra en interesser certains !!



Pour ma part, je pense m’en servir comme base pour faire des Stats sur les connexions Citrix.



Option Explicit
Dim objFSO, objFolder, objShell, objTextFile, objFile, objFarm, objSession
Dim strDirectory, strFile, strText
strDirectory = "X:"
strFile = "citrix_user_list.csv"
'strText = "List of Logged in users"

' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
End If

If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
End If

Set objFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")
objFarm.Initialize(1)

set objFile = nothing
set objFolder = nothing
' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 2

Set objTextFile = objFSO.OpenTextFile _
(strDirectory & strFile, ForAppending, True)

For Each objSession In objFarm.Sessions
strText = "User name " & objSession.UserName & " IP Address " & objSession.ClientAddress

objTextFile.WriteLine(strText)
Next
' Writes strText every time you run this VBScript
objTextFile.Close

' Bonus or cosmetic section to launch explorer to check file
If err.number = vbEmpty then
Set objShell = CreateObject("WScript.Shell")
objShell.run ("Explorer" &" " & strDirectory & "" )
Else WScript.echo "VBScript Error: " & err.number
End If