?
Solved

Add Citrix IP &  Protocol to vba script

Posted on 2012-09-04
7
Medium Priority
?
1,070 Views
Last Modified: 2012-09-26
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
0
Comment
Question by:epmmis
  • 3
  • 3
7 Comments
 
LVL 9

Expert Comment

by:Vijaya Reddy Pinnapa Reddy
ID: 38364790
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
 
LVL 23

Assisted Solution

by:Ayman Bakr
Ayman Bakr earned 2000 total points
ID: 38366557
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
 

Author Comment

by:epmmis
ID: 38368834
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 23

Expert Comment

by:Ayman Bakr
ID: 38369603
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
 

Author Comment

by:epmmis
ID: 38376310
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
 
LVL 23

Accepted Solution

by:
Ayman Bakr earned 2000 total points
ID: 38378960
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
 

Author Closing Comment

by:epmmis
ID: 38437704
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

#Citrix #XenApp #Citrix Scout #Citrix Insight Services #Microsoft VMMAP #Microsoft ADEXPLORE #Microsoft RAMMAP #Microsoft TCPVIEW #Microsoft AUTORUNS #Microsoft PROCESS EXPLORER #Microsoft PROCESS MONITOR
If your vDisk VHD file gets deleted from the image store accidentally or on purpose, you won't be able to remove the vDisk from the PVS console. There is a known workaround that is solid.
How to install and configure Citrix XenApp 6.5 - Part 1. In this video tutorial we have explained step by step installation of Citrix XenApp 6.5 Server on Windows Server 2008 R2 is explained in this video. We have explained the difference between…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question