I had a request today to track application launches on an old Presentation Server 4.0 farm so we could get a good picture of application utilization and figure out what apps needed to be migrated to newer XenApp farms and what could be decommissioned. EdgeSight has an excellent “Published Application Launch Summary” report but it it needs the EdgeSight agent to be installed in “Advanced” mode to work. This requires a Platinum license and just my luck, this particular farm had an Enterprise license and all the EdgeSight agents had to be installed in “Basic” mode. So no launch data for me.
So my solution was to write a quick .vbs logon script to write each app launch to a .txt file on a file share we could monitor. Each launch would append the .txt file. Yeah, it’s a poor man’s Edgesight application launch report but it works in a pinch. Grabbing environmental variables for each session launch was easy, the tough part was grabbing the name of the Citrix application that was launched. For this I turn to Warren Simondson/Ctrl-Alt-Del IT Consultancy and their Getpubapp.exe utility:
This handy little tool will let you query what app is running in an ICA session. I had to write my script to run the executable first, store the result in a variable, combine it with my environmental variables, and then finally append the output to my text file.
Download Getpubapp.exe and stick it in a file share where all users will have permissions to write to. Create an empty .txt file called PS4launches.txt. Now create a PSLaunch.vbs file and copy in my script below:
'Citrix XenApp and Presentation Server application launch logging (works with legacy farms) 'Written by Jason Samuel - jasonsamuel.com Dim WshShell, oExec, myDateString, mytimestring Set WshShell = CreateObject("WScript.Shell") 'the getpubapp.exe tool launches Set oExec = WshShell.Exec("\\fileserver\CitrixPS4Launches\getpubapp.exe") 'wait for the process to execute and end Do While oExec.Status = 0 WScript.Sleep 100 Loop 'initialize the variable that the app name output will go to MyAppName="" 'scan and append the command output flow to MyAppName Do While oExec.StdOut.AtEndOfStream <> True MyAppName = MyAppName + oExec.StdOut.ReadLine Loop 'MyAppName is now populated with the output of getpubapp.exe 'set the date and time into variables myDateString = Date() mytimestring = Time() 'setup to write the file output Const ForReading = 1, ForWriting = 2, ForAppending = 8 Set objNetwork = CreateObject("Wscript.Network") Dim fso, f Set fso = CreateObject("Scripting.FileSystemObject") 'file share location where we're going to write the text file to (make sure all users have permission to write here) Set f = fso.OpenTextFile("\\fileserver\CitrixPS4Launches\PS4launches.txt", ForAppending, True) 'writes the data to the txt file f.Write myDateString & " " & mytimestring & " " & MyAppName & " " & wshShell.ExpandEnvironmentStrings( "%userdomain%/%username% %COMPUTERNAME% %SESSIONNAME% %CLIENTNAME%" ) & vbCrLf f.Close
WordPress is going to run the code off the page so select all or just copy and paste the script from this .txt file:
This is a quick and dirty script I figured out and wrote in just a few hours so if you add any cool modifications, please comment below. My output has some key pieces of criteria I was after which were:
-Citrix Application Name
-Citrix server name
Now it’s just a simple matter of creating a group policy and setting this as a user logon script. I keep the “Session ID” in the output so I can tell the difference between an ICA session and an RDP session initiated by an administrator.
My txt file output looks like this:
You’ll notice on the last line is was an RDP session by an administrator logging into the server so there is no published app name. You just get an extra space. If you want to work with the data, import the text file into Excel and use Text to Columns and use the spaces as deliminators. Then you can sort on any column you need.