Add Citrix IP & Protocol to vba script

The vbs script below prints out a list of all users connected to our Metafram 4.5 Citrix farm.
I need help modifying the scrip to add the following changes.

1.  Print out the client's IP address.
2.  Print out the protocol being used (RDP or ICA) (actually option)
3.  Replace each "                            " space separators with 2 tabs.

Const cMetaFrameWinFarmObject = 1
Const MFSessionStateActive = 1
Set theFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")
theFarm.Initialize(cMetaFrameWinFarmObject)
intSessionCount = 0
intActiveCount = 0
For Each oSession In theFarm.Sessions
    intSessionCount = intSessionCount + 1
    If (oSession.SessionState = MFSessionStateActive) and (oSession.SessionName <> "Console") Then
        intActiveCount = intActiveCount + 1
        WScript.Echo oSession.UserName & "          " & oSession.ServerName & "          " & oSession.ClientName & "          " & oSession.AppName & "          " & oSession.ClientAddress 
    End If
Next
WScript.Echo "Total Session Count = " & intSessionCount & vbcrlf & "Active Session Count = " & intActiveCount

Open in new window


Thanks
epmmisAsked:
Who is Participating?
 
Ayman BakrSenior ConsultantCommented:
The fact I asked about the system DSN is because this way you ensure system credentials to access the DB. However as you said it is not the problem then that's fine.

As you have discovered the issue to be with the console user, then I would suggest you to use:

On Error Resume Next

clause before printing the session information in the for loop.
0
 
Vijaya Reddy Pinnapa ReddyCommented:
Set objFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")
objFarm.Initialize(1)
For Each objSession In objFarm.Sessions
WScript.Echo "User name : " & objSession.UserName
WScript.Echo "IP Address: " & objSession.ClientAddress
Next

Open in new window


Also refer the following links,
http://forums.citrix.com/thread.jspa?threadID=31388&
http://community.citrix.com/display/xa/How+to+get+a+list+of+users+and+the+client+IP+addresses+using+Citrix+MFCOM
0
 
Ayman BakrSenior ConsultantCommented:
The IP address is already output in your code with oSession.ClientAddress.

To convert the "                 " separator with 2 Tabs, you will replace it in the code with & vbTab & vbTab.

Your code should read like this:

Const cMetaFrameWinFarmObject = 1
Const MFSessionStateActive = 1
Set theFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")
theFarm.Initialize(cMetaFrameWinFarmObject)
intSessionCount = 0
intActiveCount = 0
For Each oSession In theFarm.Sessions
    intSessionCount = intSessionCount + 1
    If (oSession.SessionState = MFSessionStateActive) and (oSession.SessionName <> "Console") Then
        intActiveCount = intActiveCount + 1
        WScript.Echo oSession.UserName & vbTab & vbTab & oSession.ServerName & vbTab & vbTab & oSession.ClientName & vbTab & vbTab & oSession.AppName & vbTab & vbTab & oSession.ClientAddress 
    End If
Next
WScript.Echo "Total Session Count = " & intSessionCount & vbcrlf & "Active Session Count = " & intActiveCount 

Open in new window

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
epmmisAuthor Commented:
It appears when a user is connected to the server's console objSession.ClientAddress is null.  This causes the script to rudely stop. Here is the error

cscript command line output
User Name:  Fred Derf
User Session  : RDP-Tcp#594
C:\shortlist.vbs(6, 1) (null): Unspecified error

wscript error message
wscript error message
0
 
Ayman BakrSenior ConsultantCommented:
How are you connecting your XenApp servers to the datastore-using System DSN? If not then change it to System DSN.

Also check this:

http://support.microsoft.com/kb/306269
0
 
epmmisAuthor Commented:
The VB Script is ran from a session's desktop while logged on to one of the Citrix servers.  It is not clear to me how the connection Mutawadi refers to is related to this error.  

When the script is started it works fine until it reaches the user logged on to the console.  Then the script drops out returning the error shown above.  So it does access the data.

In an attempt to trap the null client.address filed the code was modied.
Const cMetaFrameWinFarmObject = 1
Const MFSessionStateActive = 1
Set theFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")
theFarm.Initialize(cMetaFrameWinFarmObject)
intSessionCount = 0
intActiveCount = 0
For Each oSession In theFarm.Sessions
  intSessionCount = intSessionCount + 1
    If (oSession.SessionState = MFSessionStateActive) and (oSession.SessionName <> "Console") Then
        intActiveCount = intActiveCount + 1
          If isnull(oSession.ClientAddress) or oSession.ClientAddress = ""  then
             WScript.Echo oSession.UserName & vbTab & vbTab & oSession.ServerName & vbTab & vbTab & oSession.ClientName & vbTab & vbTab & oSession.AppName
          Else      
             WScript.Echo oSession.UserName & vbTab & vbTab & oSession.ServerName & vbTab & vbTab & oSession.ClientName & vbTab & vbTab & oSession.AppName & vbTab & vbTab & oSession.ClientAddress 
          End If
  End If
Next

Open in new window

Here is the output of the latest code.
UserName           ServerName              ClientName                   AppName                    ClientAddress
user11            SERVER5            WS-2358            Publish App Network            192.168.53.73
user3            SERVER6            WS-3777            Publish App Network            10.1.13.12
fred            SERVER6            WS-2813            Publish App Network            192.168.62.18
chsa            SERVER4            WS-3885                                    10.1.1.115

Again, when the code cycles to the console user it returns this error => list.vbs(11, 11) (null): Unspecified error

I suspect when the user is on the console the clientaddress field is either null or just not there to read.  Somehow the code needs to either filter out the console user or adapt to the clientaddress changing.
0
 
epmmisAuthor Commented:
This answer help with the format.
    you will replace it in the code with & vbTab & vbTab.

But this answer was most important because it allow the script to run to completion.
   On Error Resume Next
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.