THINREG Recursive Folder Script
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
' //////////////////////////////////////////////////////////////////// ' ///// 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
Nice script, just a small thing I noticed, is that the Cleanup function does not appear to be called and c is not cleared.
Posted by: Herschelle | October 03, 2009 at 07:59 PM
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
Posted by: Dean Flaming | October 05, 2009 at 07:55 AM
The cleanup function was corrected for in version 0.2.
Posted by: Dean Flaming | December 07, 2009 at 04:23 PM
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?
Posted by: Emerson Kenneda | December 28, 2010 at 10:49 AM
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.
Posted by: Dean Flaming | December 30, 2010 at 09:10 AM
the synchronization is taking place, it is just the apps that I am taking away permissions on are not unregistering.
Posted by: Emerson Kenneda | January 03, 2011 at 08:27 AM
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.
Posted by: Dean Flaming | January 04, 2011 at 12:14 PM
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.
Posted by: Thomas Toftebjerg | May 10, 2011 at 07:49 AM
Great article!!! Thanks for sharing this post!!!
Posted by: buy scripts | June 02, 2011 at 01:02 AM