Heaventools

   English English  Deutsch Deutsch  Русский Русский

home  products  resource tuner console  sample scripts library

Edit Icons: Replacing Icon Resource with Icon from .ICO File

This code shows the way you can change icons in EXE and DLL files using ResTuner Console.

The script adds or replaces icons in the test EXE file with icons from .ico files in the "\Demo\Src" folder. After that, it outputs the resulting resource tree to a log file and/or the console screen. The modified file is saved to the Destination folder.

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.

'------------------------------------------------------------------------------
'
' This code shows how to modify icons in executables:
'   - Replace the main icon with the new icons from an .ICO file (including  
'     the 256x256 PNG-compressed Vista icon); 
'   - Sort out the added icons in the right order; 
'   - Add one more icon to the newly created Icon Group; 
'   - Output the changes in the Resource Tree to a log file;
'   - Restore the original timestamps on the file after saving. 
'
' The script will add or replace icons in DemoApp1.exe with icons from .ico
' files in the "Src" folder. 
'
' The resulting files will be created in the directory named "Release"
' Check the log file 'rtc.log' to see the Resource Tree changed.
'  
' For greater details, see the Step by Step Guide To Using Scripts  
'
'------------------------------------------------------------------------------

Sub Main
  PEFileProxy.PostDebugString "Updating the checksum in the PE file header is enabled." 
  PEFileProxy.UpdateCheckSum = True 

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

  PEFileProxy.PostDebugString "Open file..."
  PEFileProxy.OpenFile ".\demo\src\DemoApp1.exe"
  if (PEFileProxy.Terminated) then
    PEFileProxy.PostDebugString "Opening a file produced a fatal error."
  else
    PEFileProxy.PostDebugString "File successfully opened."
    if (not PEFileProxy.HasResources) then
      PEFileProxy.PostDebugString "The file contains no resources."
    else
      PEFileProxy.PostDebugString "The file contains resources."

      LangID = 0 ' Default

      PEFileProxy.PostDebugString "Changing/adding the main application icon..."
      ResourcesProxy.ChangeIcon "", LangID, CREATE_IF_NOT_EXIST, REPLACE_IF_ITEM_EXISTS,
 ".\src\vista_iconset.ico"

      PEFileProxy.PostDebugString "Adding an icon group NewGroup with two new icons..."
      ResourcesProxy.ChangeIcon "NewGroup", LangID, CREATE_IF_NOT_EXIST, REPLACE_IF_ITEM_EXISTS,
 ".\demo\src\icon_3_32x32_8bit.ico"
      ResourcesProxy.ChangeIcon "NewGroup", LangID, CREATE_IF_NOT_EXIST, REPLACE_IF_ITEM_EXISTS,
 ".\demo\src\icon_4_16x16_32bit.ico"

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

      PEFileProxy.PostDebugString ""
      PEFileProxy.PostDebugString "Resource Tree built by RTC:"
      ResourcesProxy.ResourceTreeToLog
      PEFileProxy.PostDebugString ""

      PEFileProxy.PostDebugString "Saving changes to a new file..."
      PEFileProxy.SaveAsNewImage ".\demo\release\DemoApp1.exe"
    end if
    PEFileProxy.PostDebugString "Closing this file..."
    PEFileProxy.CloseFile
  end if
end Sub
'------------------------------------------------------------------------------

Once you run the script, RTC outputs the Resource Tree to a log file, so you can see the changes made:

Resource Tree built by RTC:
----------------------------------------
 [Cursor (1)]
     1: 32x32 1b, Neutral (0)
     2: 32x32 1b, Neutral (0)
     3: 32x32 1b, Neutral (0)
     4: 32x32 1b, Neutral (0)
     5: 32x32 1b, Neutral (0)
     6: 32x32 1b, Neutral (0)
     7: 32x32 1b, Neutral (0)
 [Bitmap (2)]
     BBABORT: Neutral (0)
     BBALL: Neutral (0)
     BBCANCEL: Neutral (0)
     BBCLOSE: Neutral (0)
     BBHELP: Neutral (0)
     BBIGNORE: Neutral (0)
     BBNO: Neutral (0)
     BBOK: Neutral (0)
     BBRETRY: Neutral (0)
     BBYES: Neutral (0)
     CDROM: Neutral (0)
     CLOSEDFOLDER: Neutral (0)
     CURRENTFOLDER: Neutral (0)
     EXECUTABLE: Neutral (0)
     FLOPPY: Neutral (0)
     HARD: Neutral (0)
     KNOWNFILE: Neutral (0)
     NETWORK: Neutral (0)
     OPENFOLDER: Neutral (0)
     RAM: Neutral (0)
     UNKNOWNFILE: Neutral (0)
     XCLR_BMP: German - Switzerland (2055)
 [Icon (3)]
     * 1: 32x32 4b, Russian (1049)
     2: 32x32 8b, Russian (1049)
     + 3: 16x16 4b, Neutral (0)
     + 4: 32x32 8b, Neutral (0)
     + 5: 32x32 4b, Neutral (0)
 [String (6)]
     4080: Neutral (0)
     4081: Neutral (0)
     4082: Neutral (0)
     4083: Neutral (0)
     4084: Neutral (0)
     4085: Neutral (0)
     4086: Neutral (0)
     4087: Neutral (0)
     4088: Neutral (0)
     4089: Neutral (0)
     4090: Neutral (0)
     4091: Neutral (0)
     4092: Neutral (0)
     4093: Neutral (0)
     4094: Neutral (0)
     4095: Neutral (0)
     4096: Neutral (0)
 [RC Data (10)]
     DVCLAL: Neutral (0)
     PACKAGEINFO: Neutral (0)
     TFORM1: Neutral (0)
 [Cursor Group (12)]
     32761: Neutral (0)
     32762: Neutral (0)
     32763: Neutral (0)
     32764: Neutral (0)
     32765: Neutral (0)
     32766: Neutral (0)
     32767: Neutral (0)
 [Icon Group (14)]
     * MAINICON: Russian (1049)
     XCLR_ICON: German - Switzerland (2055)
     + 1: Neutral (0)
 [Version (16)]
     1: English (US) (1033)
----------------------------------------
Legend: [Name (Ord)] - Type; "+" - New; "-" - Deleted; "*" - Modified

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 in the directory where RTC has been installed. Within this Demo folder, there are 11 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.

 

The Complete Illustrated Step by Step Guide To Using Scripts

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