Heaventools

   English English  Deutsch Deutsch

home  products  resource tuner console  sample scripts library

Edit Strings: Batch Replacing Text Strings in StringTables

This code allows you to edit the StringTable and MessageTable entries in your executable files. You can modify multiple entries across several files simultaneously, and you can perform these edits repeatedly whenever necessary.

The provided VBScript code offers a real-world example that showcases the diverse capabilities of Resource Tuner Console. This code demonstrates how to:

  • Modify a String Table using values from an external Unicode text file.
  • Add a Message Table using values from another external Unicode text file.

The script effectively modifies strings in the DemoApp1.exe file, which is included in the RTC package, using string literal values from the following sources:

  • definition filedemoapp1.drc in the "\Defs" folder.
  • Unicode text file strings.txt in the "\Src" folder.
  • Unicode text filemessages.txt in the "\Src" folder.

The resulting files with updated StringTable and MessageTable entries will be saved in the directory named "Release".

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 Strings

Sub Main
  PEFileProxy.PostDebugString "PE file header checksum updating is enabled." 
  PEFileProxy.UpdateCheckSum = True

  PEFileProxy.PostDebugString "The creation of a backup copy is disabled." 
  PEFileProxy.CreateBackUp = False

  PEFileProxy.PostDebugString "Open file..."
  PEFileProxy.OpenFile ".\src\DemoApp1.exe"
  if (PEFileProxy.Terminated) then
    'Issue a warning in case of error
    PEFileProxy.PostDebugString "Error when opening this file."
  else
    PEFileProxy.PostDebugString "File opened OK."
    if (not PEFileProxy.HasResources) then
      PEFileProxy.PostDebugString "The file contains no resources."
    else
      PEFileProxy.PostDebugString "The file contains resources."

      PEFileProxy.ClearDefinitions
      PEFileProxy.PostDebugString "Opening a definition file..."
      PEFileProxy.OpenDefinitionFile ".\defs\demoapp1.drc"
      'This specifies the default language
      LangID = 0 ' Default

      PEFileProxy.PostDebugString "Editing String Table using TXT file..."
      ResourcesProxy.EditStringTableFromFileW LangID, CREATE_IF_NOT_EXIST,
".\src\strings.txt"

      PEFileProxy.PostDebugString "Adding a New Message Table using TXT file"
      ResourcesProxy.EditMessageTableFromFileW "1", LangID, CREATE_IF_NOT_EXIST,
".\src\messages.txt"

      PEFileProxy.PostDebugString "Compiling all changes..."
      PEFileProxy.Compile

      PEFileProxy.PostDebugString "Saving file as a new file..."
      PEFileProxy.SaveAsNewImage ".\release\DemoApp1.exe"
    end if
    PEFileProxy.PostDebugString "Closing this file..."
    PEFileProxy.CloseFile
  end if
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.