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:
http://www.ctrl-alt-del.com.au/CAD_TSUtils.htm
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
'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 |
If the code runs off the page above just select all or just copy and paste the script from this .txt file (right click – save as):
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:
-Date
-Time
-Citrix Application Name
-Domain/UserID
-Citrix server name
-Session ID
-Client 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.
Jason Samuel is a visionary product leader and trusted advisor with a proven track record of shaping strategy and driving technology innovation. With extensive expertise in enterprise end-user computing, security, cloud, automation, and virtualization technologies, Jason has become a globally recognized authority in the IT industry. His career spans consulting for hundreds of Fortune 500 enterprises across diverse business sectors worldwide, delivering cutting-edge digital solutions from Citrix, Microsoft, VMware, Amazon, Google, and NVIDIA that seamlessly balance security with exceptional user experiences.
Jason’s leadership is amplified by his dedication to knowledge-sharing as an author, speaker, podcaster, and mentor within the global IT and technology community. Recognized with numerous prestigious awards, Jason’s contributions underscore his commitment to advancing technology and empowering organizations to achieve transformative results. Follow him on LinkedIn.
Morten
December 10, 2013 at 2:59 AM
This is great. The only caveat is with session sharing in that only the actually launched application is recorded. Even running getpubapp manually when more published apps had been started only showed the original app.
Still very useful though. Thanks a lot!
Jason Samuel
December 10, 2013 at 10:50 AM
Thanks Morten. You are absolutely right. Getpubapp.exe only returns the result of the first app that was launched in the session. Additionally since the script is set to run at user logon it will only run once when the first app on the server is launched. All subsequent app launches in the same session will not trigger the script. It’s a bit of a limitation. Let me see what I can come up with.
Warren Simondson
March 3, 2014 at 4:03 AM
Hi Jason
That’s a great use of getpubapp.exe. I wrote that exe a long time ago, but I’m interested in what you are doing here. Let me know what you need from it and I might be able to write a modification. There’s certainly no reason why you can’t enumerate the sessions within the session, by enumerating the user sessions against the farm and listing them against the client name. I’d certainly be interested in helping out.
Cheers
Warren Simondson
Jason Samuel
March 3, 2014 at 3:56 PM
@Warren Simondson
Hey Warren, thanks for your comment and making getpubapp available! Yes it would be great if it could pass all apps the user opens.
Todd
June 18, 2014 at 9:59 AM
This works great for the initial connection. Any ideas for capturing session sharing information?
Thanks,
Todd