Home > Blogs > VMware ThinApp Blog


Using a VB Script to Time-Bomb a ThinApp Package

Ever wonder how one could use a VB Script to Time-Bomb a ThinApp package? Well, awhile back this was discussed in the Scripting Within ThinApp session of the ThinApp Bootcamp Series! Here’s how it’s done!

Script Info:

Basically, the way the script works is by looking at the ThinApp data container date/time stamp and comparing it to the date/time of the system. While this is not infallible, it does give Administrators some control as this would essentially force a user to need the ability to change their system time.

Known Issues:

Expiration checks are only done during initial launch of the ThinApp Packaged app containing this script. Once the application is running, this will not continue checking nor terminate the already running ThinApp.

Additionally, while some date mod detections do exist in the script, users with abilities to change the date on their system will have the ability to circumvent this by simply setting the date to something within the valid period between the modification date and the number of days the package is valid.

Lastly, the script does not accommodate for time zone differences. If you set a ThinApp package to expire one a specific date and you change your system’s time zone to match your locale, if the update to the time zone forces you to jump to or past the expiration date then the ThinApp package will stop working by design.

The Code:

ThinApp Time Bomb Script.txt – RIGHT CLICK and SAVE AS.




AdminScriptEditor Script Conversion


'========================================================
'Script Information:
'===================
'Title:                         ThinApp Expiration Date Scipt
'Author:                         Dean Flaming
'Originally created:     10/04/2011
'
'Description:
'============
'Used to expire a ThinApp Package after a set period of days
'
'Known Issues:
'=============
'Expiration checks are only done during initial launch of
'the ThinApp Packaged app containing this script. Once the
'application is running, this will not continue checking nor
'terminate the already running ThinApp.
'
'Additionally, while some date mod detections do exist in
'the script, users with abilities to change the date on
'their system will have the ability to circumvent this by
'simply setting the date to something within the valid
'period between the modification date and the number of days
'the package is valid.
'========================================================

' DECLARE VARIABLES
Dim WSHNetwork, WSHShell, objFSO, objShell, objWMIService, strComputer
Dim TSOrigin, TSCurProcName, TSSourcePath
Dim GCPOrigin, GCPLastSlash, GCPSourcePath, GCPCurProcName
Dim SandboxParent, SandboxName, SandboxPath
Dim strFilePropDateCreated, strFilePropDateModified
Dim strSelfDestruct, strFileAgeLimit, strFileWarning
strComputer = "."
' SET GLOBAL VARIABLES
Set WSHNetwork = CreateObject("WScript.Network")
Set WSHShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
' DEFINE SCRIPT ENVIRONMENT VARIABLES
strFileAgeLimit = 10  'This is the number of days after which to expire the ThinApp package
strFileWarning = 5  'This is the number of days left which to start warning the user.

'Find the Entry Point Process Name
TSOrigin = GetEnvironmentVariable("TS_ORIGIN")
TSLastSlash = InStrRev(TSOrigin, "\")
TSSourcePath = Left(TSOrigin, TSLastSlash)
TSCurProcName = Mid(TSOrigin, TSLastSlash + 1, Len(TSOrigin))
'Find the Current Process Name
GCPOrigin = GetCurrentProcessName
GCPLastSlash = InStrRev(GCPOrigin, "\")
GCPSourcePath = Left(GCPOrigin, GCPLastSlash)
GCPCurProcName = Mid(GCPOrigin, GCPLastSlash + 1, Len(GCPOrigin))
'Find the Sandbox Name and Path
SandboxParent = GetBuildOption("SandboxPath")
SandboxName = GetBuildOption("SandboxName")
If SandboxParent = "." Then
SandboxPath = SourcePath & SandboxName
Else
SandboxPath = SandboxParent & Chr(92) & SandboxName
End If
Function OnFirstSandboxOwner
'
End Function
Function OnFirstParentStart
'Check ThinApp Package Age
     CheckAge
End Function
Function OnFirstParentExit
'
End Function
Function OnLastProcessExit
'
End Function
Function CheckAge
' ATTACH TO THINAPP PACKAGE, FIND DATE MODIFIED, & DETERMINE AGE
     If objFSO.FileExists(TSOrigin) Then
Set objFile = objFSO.GetFile(TSOrigin)  'Attach to the ThinApp Package File
          strFilePropDateCreated = objFile.DateCreated  'Capture the Date Created - Not Used
          strFilePropDateModified = objFile.DateLastModified  'Capture the Date Modified
          strCurrentDateTime = Now  'Capture Current System Date and Time
          strFileAge = DateDiff("d", strFilePropDateModified, strCurrentDateTime)  'ThinApp file Age Calculation

'BEGIN TEST CODE
          'strFileAge = DateDiff("d", strFilePropDateModified, strCurrentDateTime) + strFileAgeLimit - 1  'Artificial date modification for testing
          'MsgBox "The file '" & GCPCurProcName & "' was created or last modified on " & strFilePropDateModified & "." & vbCrLf & vbCrLf & "Current Date is " & strCurrentDateTime & vbCrLf & vbCrLf & "The file's is " & strFileAge & " days old.",, "Test Message"
          'END TEST CODE

If strFileAge > strFileAgeLimit Then  'If the File Modification age is beyond the defined age limit then notify the user and terminate the ThinApp Package
               MsgBox "The application '" & GCPCurProcName & "' has reached 'End-of-Life' and will be terminated!",, "Application End of Life!"
ExitProcess 0 'Exit the current process
          Else
If strFileAge < 0 Then  'If the File Modification age is a negative number then the system time is set previous to the file modification date and should be seen as circumvention.
                    MsgBox "The file '" & GCPCurProcName & "' has a date newer than the current system date!" & vbCrLf & vbCrLf & "This is an indication attempts are being made to circumvent the End-of-Life feature!!  This application will be terminated!",, "Application End of Life Circumvention Detected!"
ExitProcess 0 'Exit the current process
               End If
If (strFileAgeLimit - strFileAge) < strFileWarning Then
MsgBox "This ThinApp Packaged application will expire in " & (strFileAgeLimit - strFileAge) & " days!" & vbCrLf & vbCrLf & "Please contact this ThinApp Package Administrator for a newer version and assistance!",, "Application End of Life Near!"
End If
End If
Else  'If TSOrigin no longer exists, then this indicates tampering while the ThinApp package is running and the package should be closed.
          MsgBox "The file '" & GCPCurProcName & "' could not be found!" & vbCrLf & vbCrLf & "The application will be terminated!",, "FILE NOT FOUND!"
ExitProcess 0 'Exit the current process
     End If
End Function


This entry was posted in Integration, Scripts, Tips and tagged , , on by .
Dean Flaming

About Dean Flaming

Dean is currently an EUC Architect and member of the VMware End User Computing Enablement and Lighthouse Support teams, working to develop communications and IP around VMware End User Computing products and solutions as well as support many various Lighthouse accounts with their own EUC practices. Prior to this, from 2008 through 2012 Dean was one of VMware’s End User Computing Specialists. Throughout his time at VMware, Dean has also written and published various articles, videos, and podcasts regarding VMware’s EUC Solutions.