Heaventools

   English English  Deutsch Deutsch

Batch Processing All Executable Files in a Folder

This sample code provides a real-world example that demonstrates many of the features available in Resource Tuner Console. The code shows how to batch process the contents of a directory.

The script scans the specified Source directory for all files available. Then, for each file with given file extension (EXE, DLL, SYS) it calls for the ProcessFile procedure to set the English-US language for all of the resources in the file and update the Version Information. The resulted files are saved to the Destination directory.

Note: when copying out the script code, please make sure there's no line breaks. This is a requirement of VBScript: the entire command must be on one line.

Process Folder

'---------------------------------------------------------------------------------
'
' This code shows how to batch process the contents of a directory.
' It processes specific file extensions (EXE, DLL, SYS) in the source directory.
'
'---------------------------------------------------------------------------------
' ProcessFile procedure
' 
' Purpose:
' 
' It sets the English-US language for all of the resources
' in the file and updates the Version Information resource:
' StringFileInfo, FileVersion and ProductVersion values.
'
'---------------------------------------------------------------------------------

Sub ProcessFile (SrcPath, DestPath, FileName)
  ' Set Language constant here
  LangID = 1033 ' English-US
  
  ' Retrieve the Code Page
  CP     = ScriptUnit.CodePageFromLangID(LangID)
  
  PEFileProxy.OpenFile SrcPath & FileName
  If Not PEFileProxy.Terminated Then
    If PEFileProxy.HasResources Then 
      ResourcesProxy.SetLanguage LangID, DELETE_IF_EXISTS 
      If ResourcesProxy.OpenVersionInfo("1", LangID, CREATE_IF_NOT_EXIST) Then 
       VersionInfoProxy.SetFileVersion  2, 0, 1, 122, LangID, True, True, True
       VersionInfoProxy.SetProductVersion 2, 0, 0, 0, LangID, True, True, True
       S1 = "Copyright \0xA9 2024 SuperSoftware Development"
       S2 = "SuperProg is a trademark of SuperSoftware Development"
       S3 = "This file modified by Resource Tuner Console"
       VersionInfoProxy.EditStringFileInfo "LegalCopyright", S1, CP, LangID, True, True
       VersionInfoProxy.EditStringFileInfo "LegalTrademarks", S2, CP, LangID, True, True
       VersionInfoProxy.EditStringFileInfo "Comments", S3, 1049, LangID, True, True
       ResourcesProxy.CloseVersionInfo 
       PEFileProxy.Compile 
       PEFileProxy.SaveAsNewImage DestPath & FileName 
      Else
        ' Issue a warning in case of error
        PEFileProxy.PostDebugString "Failed to open/create Version Info..." 
      End If 
    End If 
  End If 
End Sub 

'------------------------------------------------------------------------------ 
' 
' The main routine. 
' 
' First, it scans the specified Source folder for files available. 
' Then, for each file found it calls for the ProcessFile procedure. 
'
' Resource Tuner Console Demo allows you to process only two files at a time.
' Order the full version and enjoy it without limitations!
' 
'------------------------------------------------------------------------------

Sub Main 
  dim SrcPath, DestPath, File_System_Object, Folder_Object, File_Object, File_Collection
  PEFileProxy.UpdateCheckSum = True 
  PEFileProxy.CreateBackUp   = False
  
  ' Specify the path to the Source Folder
  SrcPath = ScriptUnit.CurrentFolder & "src\"
  
  ' Specify the path to the Destination Folder
  DestPath = ScriptUnit.CurrentFolder & "release\"
  
  ' Scan the specified folder and process all files found.
  set File_System_Object = CreateObject("Scripting.FileSystemObject")
  set Folder_Object      = File_System_Object.GetFolder(SrcPath)
  set File_Collection    = Folder_Object.Files
  for each File_Object in File_Collection
  ' Get an extension and modify it to one uniform lower case
  ' because there may be both upper and lower case characters
    FL_EXT = LCase(File_System_Object.GetExtensionName(File_Object.name))
  ' Check an extension and process specific file extension
    If FL_EXT = "exe" or FL_EXT = "dll" or FL_EXT = "sys" Then
      ProcessFile SrcPath, DestPath, File_Object.name
      PEFileProxy.PostDebugString "*************************************"
    End If
  Next
End Sub

To see the changes made to the test EXEs, we recommend using Resource Tuner GUI, a visual resource editor.

Once installed Resorce Tuner Console, you will find the Demo folder nested in the directory where RTC has been installed. Within this Demo folder, there are 12 subdirectories that contain sample scripts and sample executable files.

All sample scripts are ready to run. Select one of the .BAT files located in the Demo folders to execute the sample script. The script will make changes in the test EXE file. The resulting file will be created in the directory named "Release" under the directory containing the script.

 Download Resource Tuner Console and learn how it can make you more productive.