VMware

Running IE6 on a Windows XP with IE8 locally installed. | Main | Integrating ThinApp Packages with VMware View – Part 1

October 03, 2009

THINREG Recursive Folder Script

UPDATED!! Ever stop and wish the THINREG.EXE tool would search all subfolders and register apps in them? Rest assured, it is a feature request which has been input to our product development team.

But why wait?? Phil Helming (VB Scripter Extraordinaire) has put together a really nice VBS Script to be used within a login process which accommodates subfolders nicely!

Updates:

  • Fixed issue where script wouldn't register apps in same folder as script.
  • Correctly called cleanup code



AdminScriptEditor Script Conversion
' ////////////////////////////////////////////////////////////////////
' ///// DO NOT MODIFY THIS SCRIPT UNLESS SPECIFICALLY INSTRUCTED /////
' ////////////////////////////////////////////////////////////////////
'
' ////////////////////////////////////////////////////////////////////
'
' usage               : Execute this script manually or via logon script / desktop management
' description          : Script to search folder for *.exe files and run thinreg.exe against them
' author               : Phil Helmling (phelmling@vmware.com)
' filename          : Thinreg_recursively_v0.2.vbs
' version               : 0.2
' gpo               : n/a
' history:          : 17/09/09 initial release (Phillip Helmling)
'                      01/12/09 updated Iterate function as well as cleanup
' syntax               : none
' parameters          : none
' files               : none
'
' ////////////////////////////////////////////////////////////////////
     
     Option Explicit
     
'     Const ForReading     = 1, ForWriting = 2, ForAppending = 8, OverwriteExisting = True, NoOverwrite = False
     
'-----------------------------------------
'     Global Variables 
'-----------------------------------------

     Dim oShell     ' Shell for the script
     Dim oNet     ' Network for the script
     Dim oFSO     ' File System object for the script
     Dim oFile     ' File for the script
     Dim aFolder, aFolderRoot, aFile, SubFolder     ' Used to iterate through the fixed disks
     Dim incldic, incldic1, excldic, excldic1, a, a1, c, c1, i     ' Dictionaries
     Dim sPath, sCurrentPath ' Used for current directory and log file
     Dim sThinappshare, sThinregexe
     Dim f, Items, aItem

'-----------------------------------------
'     Objects 
'-----------------------------------------

     Set oShell      = WScript.CreateObject("Wscript.Shell")
     Set oNet      = WScript.CreateObject("Wscript.Network")
     Set oFSO      = WScript.CreateObject("Scripting.FileSystemObject")
     Set a           = WScript.CreateObject("Scripting.Dictionary")
     Set c           = WScript.CreateObject("Scripting.Dictionary")

'-----------------------------------------
'     Set Variables including source and destinations
'-----------------------------------------
     
     sPath = WScript.ScriptFullName
     sCurrentPath = Left(sPath, InStrRev(sPath, "\"))
     sThinappshare = sCurrentPath                     ' you can have the script start from the same directory as the script
'     sThinappshare = "\\SERVER\THINAPP_SHARE\"          ' or you can specify a drive:\folder structure or \\server\share

     sThinregexe = sThinappshare & "thinreg.exe"          ' you can run thinreg.exe from the same directory as the script
'     sThinregexe = "\\SERVER\THINAPP_SHARE\thinreg.exe"     ' or you can specify a drive:\folder structure or \\server\share

'-----------------------------------------
'     List extensions to search for in an array
'-----------------------------------------

     a.Add "a", "exe"
     incldic = a.Items   ' Get the items.
     For i = 0 To a.Count -1 ' Iterate the array.
          a1 = a1 & incldic(i) & ", " ' Create return string.
     Next
     incldic1 = a1

'-----------------------------------------
'     List directories to exclude
'-----------------------------------------

     ' Exclude all folders with the follow names
     c.Add "a", "System Volume Information"
     c.Add "b", "RECYCLER"
     c.Add "c", "Temp"
     c.Add "d", "Temporary Internet Files"
     c.Add "e", "plugins"
     c.Add "f", "tools"
     c.Add "g", "Other"
     c.Add "h", "MSOffice2k7"
     c.Add "i", "MSOffice97"

     excldic = c.Items   ' Get the items.
     For i = 0 To c.Count -1 ' Iterate the array.
          c1 = c1 & excldic(i) & ", " ' Create return string.
     Next
     excldic1 = c1

'-----------------------------------------
'      Main Program - Search all folders listed above
'-----------------------------------------

     Set aFolderRoot = oFSO.GetFolder(sThinappshare) 
     Call SearchFolder(aFolderRoot)

     Call Cleanup

'-----------------------------------------
'     Subs
'-----------------------------------------

     Sub SearchFolder(aFolder)
          On Error Resume Next
          Call Iterate(aFolder)
               
          ' Searching subfolders
          For Each SubFolder In aFolder.SubFolders
               SearchFolder SubFolder
          Next
     End Sub

     Sub Iterate(aFolder)
          On Error Resume Next
'          wscript.echo "Iterating through " & aFolder
          
          ' Folder Name not searched
          For Each aItem In c.Items
               If aFolder = sThinappshare Then
                    ' continue
               Else If InStr(excldic1, aFolder.Name) <> 0 Then Exit Sub
               End If
          Next

           For Each aFile In aFolder.Files
               If aFile.Name = "thinreg.exe" Then
                    ' do nothing
               ElseIf aFile.Name <> "" Then
                    If aFile.Name <> "" Then
                         If InStr(incldic1, Right(aFile.Name, 3)) <> 0 Then
'                              Wscript.Echo Chr(34) & sThinregexe & Chr(34) & " /q /norelaunch " & Chr(34) & aFile & Chr(34)
                              oShell.Run Chr(34) & sThinregexe & Chr(34) & " /q /norelaunch " & Chr(34) & aFile & Chr(34), 1, True ' register
'                              oShell.Run Chr(34) & sThinregexe & Chr(34) & " /u " & Chr(34) & aFile & Chr(34), 1, True ' unregister
                         Else
                         End If
                    End If
               End If
          Next
     End Sub

     Function Cleanup
          '      Clean up the objects and close the script
          Set oShell = Nothing
          Set oNet = Nothing
          Set oFSO = Nothing
          Set a = Nothing
          Set c = Nothing
          WScript.Quit
     End Function


Here's the script in it's entirety.
Download Thinreg_recursively_v0.2.vbs

Thanks Phil for a great piece of code!!

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8341c328153ef0120a61096f5970c

Listed below are links to weblogs that reference THINREG Recursive Folder Script:

Comments

Herschelle

Nice script, just a small thing I noticed, is that the Cleanup function does not appear to be called and c is not cleared.

Dean Flaming

Good point....you'd probably want to call that function separately anyways from the end of your login script though.

For an example login script, see http://blogs.vmware.com/thinapp/2008/10/thinapp-thinreg.html

Dean Flaming

The cleanup function was corrected for in version 0.2.

Emerson Kenneda

I am trying to use this script and I seeming to be running into an issue. I have the script run when the user logs in and the thinapps that I give the AD Security Groups permission to are showing up. The issue I am seeing is that when I take permissions way they sign back in the software is still there, they aren't able to open the software but it is still showing visable. Any suggestions?

Dean Flaming

If you have multiple domain controllers, AD synchronization can take some time (depends upon the settings you have configured for domain synchronization - and while password changes and account disablement forces immediate synchronization, group membership changes do not).

If you go into AD Sites and Services, you can force the synchronization of your domain controllers.
See Microsoft Technet at http://technet.microsoft.com/en-us/library/cc776188%28WS.10%29.aspx for more info on forcing domain synchronization.

For changing the default synchronization intervals, see Microsoft's KB 214678 at http://support.microsoft.com/kb/214678 for more info.

Emerson Kenneda

the synchronization is taking place, it is just the apps that I am taking away permissions on are not unregistering.

Dean Flaming

I would suggest trying manually with THINREG.EXE /U [PATH\APP.EXE] as well as removing user from group, logging out and back in, then manually trying THINREG.EXE [PATH\APP.EXE] (no /U switch).

If you're having an issue where removing the user from the group (and logging out and back in) doesn't automatically remove the app from the user's desktop (assuming THINREG.EXE is part of your user's login script), please ensure you are on the latest version of ThinApp 4.6 (download from VMware.com) and the package is built with ThinApp 4.6 (capturing with 4.6 is not needed, only building with 4.6 is).

If you are still having issues after all of this, please do contact VMware Support on the web at http://www.vmware.com/support or by phone at 1-877-4-VMWARE (1-877-486-9273) or 1-650-475-5345.

Thomas Toftebjerg

Script stopped when user did not have read access to one of the subfolders. solved it by moving the "On error resume Next" from line 108 to line 112.

buy scripts

Great article!!! Thanks for sharing this post!!!

Post a comment

If you have a TypeKey or TypePad account, please Sign In.

About this Blog

VMware ThinApp lets you deliver and deploy applications more efficiently, more securely, and more cost-effectively with agentless application virtualization.

Subscribe via RSS  

Or submit your email for updates:

End-User Computing Blog


Read additional blog posts for VMware ThinApp on the VMware End-User Computing Blog.

Visit Now

Search ThinApp Blog

Community


Discussions and resources for VMware ThinApp

Visit now

Twitter


Facebook

YouTube


    VMware Blogs