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)



Keine Kommentare:

Kommentar veröffentlichen