Heaventools

   English English  Deutsch Deutsch

home  products  resource tuner console  sample scripts library

Changing Version Variables And Updating The Version Information

This code demonstrates how to change version variables (version numbers, product names, copyright strings, and more) in all existing Windows EXE, DLL, or RES files within a specified folder.

Resource Tuner Console provides a convenient way to modify version variables directly from the command line. If a file does not already contain Version Info resource, Resource Tuner Console will create and add this resource for you.

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.

Edit Version Information

sub ProcessFile (SrcPath, DestPath, FileName)
  ' Set the language constant value to English-US
  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

'--------------------------- Set the language --------------------------------------
      'Set the English-US language for all of the resources in the file.
      ' It modifies the language for all resources in the file to one uniform value. 
      ' This operation is optional: if you don't need to modify the language for 
      ' resources, you can simply comment it out.      
      ResourcesProxy.SetLanguage LangID, SKIP_IF_EXISTS
'-----------------------------------------------------------------------------------

      'Open the Version Info for editing.      
      if ResourcesProxy.OpenVersionInfo("1", LangID, CREATE_IF_NOT_EXIST) then
	  
        VersionInfoProxy.SetFileVersion  5, 1, 4, 20, LangID, True, True, True
        VersionInfoProxy.SetProductVersion 5, 1, 0, 0, LangID, True, True, True

        S1 = "My Company"
        S2 = "Yet Another Super Application"
        S3 = "Hot product"
        S4 = "Copyright \0xA9 2024 My Company, Inc."
        S5 = "your trademarks here..."
        S6 = "Next Big Thing"
        S7 = "Powered by Resource Tuner Console"

      VersionInfoProxy.EditStringFileInfo "CompanyName", S1, CP, LangID, True, True
      VersionInfoProxy.EditStringFileInfo "FileDescription", S2, CP, LangID, True, True
      VersionInfoProxy.EditStringFileInfo "InternalName", S3, CP, LangID, True, True
      VersionInfoProxy.EditStringFileInfo "LegalCopyright", S4, CP, LangID, True, True
      VersionInfoProxy.EditStringFileInfo "LegalTrademarks", S5, CP, LangID, True, True
      VersionInfoProxy.EditStringFileInfo "ProductName", S6, CP, LangID, True, True
      VersionInfoProxy.EditStringFileInfo "Comments", S7, CP, LangID, True, True

        ResourcesProxy.CloseVersionInfo
        PEFileProxy.Compile
        PEFileProxy.SaveAsNewImage DestPath & FileName
      else
        'Issue a warning in case of error
        PEFileProxy.PostDebugString "Can't open/create Version Info resource..."
      end if
    end if
  end if
end sub	

'----------------------------------------------------------------------------------
'
' The main routine.
'
' It processes specific file extensions in the source directory.
'
' First, it scans the specified Source directory for available files. 
' Then, for each file found with specific file extension (EXE, DLL, RES),
' it calls the ProcessFile procedure to perform the necessary modifications.
'
'----------------------------------------------------------------------------------

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 then 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 convert it to one uniform lowercase, regardless of
  ' whether the original filename contains upper or lowercase characters.   
    FL_EXT = LCase(File_System_Object.GetExtensionName(File_Object.name))

  ' Check if the file has the specified file extension and process it.
  ' Add or remove file extensions as needed.
    if FL_EXT = "exe" or FL_EXT = "dll" or FL_EXT = "res" then
      ProcessFile SrcPath, DestPath, File_Object.name
      PEFileProxy.PostDebugString "*************************************"
    end if
  Next 
End Sub

To view the changes made to the test EXE and DLL files, you can open them using Resource Tuner GUI.


SAMPLE SCRIPTS LIBRARY

Upon installing Resource Tuner Console, you will find the Demo Scripts folder nested within the RTC installation directory. This folder contains 12 subdirectories, each featuring script examples and sample executable files.

All the sample scripts are ready to run. To execute a sample script, simply select one of the .BAT files located within the respective Demo folders. When executed, the script will apply changes to the test EXE file. The resulting modified file will be created in a directory named Release, which resides in the same directory as the script.

 

The Complete Illustrated Step-by-Step Guide To Using Scripts

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