Dienstag, 24. Januar 2012

Recursive ThinReg with no Desktop flashing

You might know the script pubilshed at http://communities.vmware.com/docs/DOC-13715 to register ThinApp packages inside your ThinApp repository. This script has the side effect that the Desktops flashes each time the register function starts to register a ThinApp package. You can avoid this with the new thinreg.exe and the /nodesktoprefresh option that is not available with the curren ThinApp SDK. One easy solution is the combination of this script with thinreg.exe and that is how it looks like when using both:

' Recursive registration of ThinApp packages
'
' Usage: RecursiveRegv2.vbs
'
' RecursiveReg will register all ThinApp entry points in FolderName and in any subfolders
' The registration will be per-user. Any entry points to which the user no longer has access
' (because of the PermittedGroups setting) and which are already registered will be
' automatically unregistered.
' You need to have ThinAppSDK.dll present and registered using regsvr32.
' Zou need to have thinreg.exe Version 4.7.0 or higher in a Path location.

Option Explicit

Sub ProcessFolder(Folder, TAManagement)
Dim FolderName
FolderName = Folder.Path
' Process all files in this folder
Dim File
For Each File in Folder.Files
' Construct the full path to the file
Dim FileName
FileName = FolderName & "\" & File.Name
' We're only interested in .exe files
If UCase(Right(FileName, 4)) = ".EXE" Then
' Check if it is a ThinApp entry point.
' ThinAppType 1 = Primary data container
' ThinAppType 2 = Shortcut executable
Dim ThinAppType
ThinAppType = TAManagement.GetThinAppType(FileName)
If ThinAppType = 1 Or ThinAppType = 2 Then
' Ok, we have found a real ThinApp entrypoint. Register it,
' flag 1 means per user
Dim Package
WScript.StdOut.WriteLine "Found valid ThinApp Exe " & FileName
Set Package = TAManagement.OpenPackage(FileName)
WScript.StdOut.WriteLine "Inventory Name " & Package.InventoryName
WScript.StdOut.WriteLine "Main Data Container " & Package.MainDataContainer
WScript.StdOut.WriteLine "ThinAppVersion " & Package.ThinAppVersion
WScript.StdOut.WriteLine "Register or Unregister the Application..."
Dim MyThinReg
MyThinReg = "thinreg " & FileName & " /nodesktoprefresh"
WScript.StdOut.WriteLine MyThinReg
Dim Return
Return = WshShell.Run(MyThinReg , 1, true)
'Package.Register 1 not in use because option
End If
End If
Next

' Now do the sub folders
Dim SubFolder
For Each SubFolder in Folder.SubFolders
ProcessFolder SubFolder, TAManagement
Next
End Sub

' Check arguments
If WScript.Arguments.Count <> 1 Then
WScript.Echo "Usage: RecursiveRegv2.vbs "
WScript.Quit(1)
End If

' Create ThinApp.Management object
Dim TAManagement
Set TAManagement = CreateObject("ThinApp.Management")

' Get a Folder object through the FileSystemObject
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim Folder
Set Folder = FSO.GetFolder(WScript.Arguments(0))

Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")

WScript.StdOut.WriteLine "Start ThinApp Recursive Registration in Folder " & Folder.Name

' Now start recursively processing the folder
ProcessFolder Folder, TAManagement

' All done
WScript.Quit(0)



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

Automate the Cloud

Tie Blog contains details about how to automate the IT Cloud with solutions based on VMware Technologies.