Dienstag, 24. Januar 2012

ThinApp Clean the Sandbox at Start

I found a workaround to check for a clean sandbox each time when a user starts an ThinApp application with the Callback Function OnFirstSandboxOwner and initialize the Sandbox each time when it’s not clean with and RemoveSandboxOnExit and Exit Process API call. This works perfect with the parameter RemoveSandboxOnExit=1 inside the package.ini and you must be sure that your sandbox is clean before the application starts. The user gets a Message Box that he has to restart the application and that’s it.

And here is the Script:

Function OnFirstSandboxOwner

If CheckForCleanSandbox() <> True Then

RemoveSandBoxOnExit (1)

ExitProcess -1

End If

End Function

Function CheckForCleanSandbox()

CheckForCleanSandbox = False

FoundnotDefault = False

SandboxParent = GetBuildOption("SandboxPath")

SandboxName = GetBuildOption("SandboxName")

If SandboxParent = "." Then

SandboxPath = SourcePath & SandboxName

Else

SandboxPath = SandboxParent & Chr(92) & SandboxName

End If

If SandboxParent = "" Then

SandboxPath = "%AppData%\Thinstall\" & SandboxName

End If

'Const DbQuote = """"

'SandboxPathCheck = DbQuote & SandboxPath & DbQuote

FolderExists = objFSO.FolderExists(SandboxPath)

If (FolderExists) Then

'Sandbox exists! Check if this is a real ThinApp Sandbox folder

Regtvr = SandboxPath + "\Registry.rw.tvr"

'Check if file Registry.rw.tvr exists...")

'MsgBox Regtvr

RegtvrExists = objFSO.FileExists(Regtvr)

If (RegtvrExists) Then

'MsgBox "Registry file exists"

'File Registry.rw.tvr exists! This is a vaild ThinApp Sandbox...

'MsgBox SandboxPath

Set objFolder = objFSO.GetFolder(SandboxPath)

'Check if this a clean Sandbox environment...

Set Files = objFolder.files

Set Subfolders = objFolder.SubFolders

For Each File In Files

If File.Name = "Registry.rw.tvr" Then

'File Registry.rw.tvr is needed for Sandbox. Default file

ElseIf File.Name = "Registry.rw.tvr.lck" Then

'File Registry.rw.tvr.lck is needed for Sandbox. Default file

ElseIf File.name = "Registry.rw.tvr.transact" Then

'File Registry.rw.tvr.transact is needed for Sandbox. Default file

ElseIf File.name = "Registry.tlog" Then

'File Registry.tlog is needed for Sandbox. Default file

ElseIf File.name = "Registry.tlog.cache" Then

'File Registry.tlog.cache needed for Sandbox. Default file

Else

'Found not default file in Sandbox. Sandbox is not clean!

FoundnotDefault = true

End If

Next

For Each Folder In Subfolders

If Folder.Name ="SKEL" Then

'ThinApp Default Temp Folder. Do nothing....

Else

'Found not default folder in Sandbox. Sandbox is not clean!

FoundnotDefault = true

End If

Next

Else

MsgBox "File Registry.rw.tvr doesn't exist! It looks like this is not a valid ThinApp Sandbox..."

End If

Else

MsgBox "Your Sandbox is not valid or accessible. Please contact your ThinApp Administrator!"

End If

'Space to check for registry files that could exist in a not clean sandbox environment.

If FoundnotDefault <> True Then

'Sandbox is new

CheckForCleanSandbox = True

Else

MsgBox "You have an existing Sandbox. The Sandbox will be initialized now and the application must be restarted.",,"Check Sandbox"

CheckForCleanSandbox = False

End If

End Function

Keine Kommentare:

Kommentar veröffentlichen