Home > Blogs > VMware ThinApp Blog

ThinApp package usage metering

Nicolas Van Wijnsberghe, a colleague of mine, sent me this great example of just how flexible ThinApp and its VB-Script support is. With our VB-Script your imagination is pretty much the limitation..

Here is a VB-Script that will provide a poor mans software-metering solution.

This example uses a network share stored cvs file to register each users usage of an application. You can later use the cvs and Excel to create nice looking tables of usages. If the network share is not accessible will the script display an error message but will continue to execute the packaged application.  You could add all kind of logic to the script, e.g. kill the application if we cannot access the network path or why not use a database instead of writing to a cvs file.

This is an example of what the cvs file will look like and some generated graphs.

 Cvs output Untitled

Simply create a file in the root of your project named anything but with the extension of .vbs and copy the below script into it. Please remember to change the niopath= to fit your environment and make sure the end users have permissions to create and modify the file. This is important since the vb-script is executing in the end users content.

Function OnFirstParentStart
Dim sDst, fso, fLOut, sComputer, sUser, sNow
Dim WshShell, objEnv
Dim niopath
‘Path to csv file on share accessible by all users in domain
Set WshShell = CreateObject("WScript.Shell")
Set objEnv = WshShell.Environment("Process")
sComputer = objEnv("COMPUTERNAME")
sUser = objEnv("USERNAME")
sNow = Now
Set fso = CreateObject("Scripting.FileSystemObject")
' Check if path to csv file is correct and accessible, if not throws warning
if fso.FileExists(niopath) then
‘Open file from share
Set fLOut = fso.OpenTextFile(niopath, 8,True)
‘Write new line in csv comma delimited: format computernname,username,datetime
sDst = sComputer& "," & sUser & "," & sNow & vbCrLf
‘Clear objects in memory and exit
fLOut.Write sDst
Set fLOut = Nothing
Set fso = Nothing
Msgbox "Sorry, This Application is started without correct Network Access" & vbNewLine & vbNewLine _
& "=> Please Contact your Application Administrator at extension 007" , vbWarning, "Warning"
end if

End Function

This entry was posted in Scripts and tagged , , , , on by .
Peter Bjork

About Peter Bjork

Peter Bjork is a Senior Staff Architect, Technical Marketing at VMware. He specializes in Identity and Access Management. He's widely appreciated as a speaker at events like VMworld, VMUG and vFORUM. He is the author of two books as well as numerous white papers and blog posts. When the work day is over, Peter volunteers as a Scout leader for the local Sea Scout troop outside Stockholm, Sweden. Twitter: @thepeb.