Free Trial Software Downloads Command-line Resource Editor
Heaventools Home
 

home      products      solutions     news     downloads     order     support     about us

 

 
Resource Tuner Console Sample Scripts
 

 

Edit Icons

Add or replace Icons from .ico or .png files

This code shows the way you can replace icons in EXE and DLL files using VBScript with Resource Tuner Console.

The script adds or replaces icons in the demo EXE (which shipped with the RTC package) with icons from .ico files in the "..\Demo\Src" folder. It also outputs the resource tree to a log file and/or the console screen. The resulted file is saved to the Destination folder.

'------------------------------------------------------------------------------
'
' This code shows how to modify icons in executables.
'
' The script will add or replace icons in demoapp1.exe with icons from .ico
' files in the "..\Demo\Src" folder. 
'
' The resulting files will be created in the directory named "..\Demo\Release"
' Check the log file to see the Resource Tree built. 
'
'------------------------------------------------------------------------------

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 

  LangID = 0 ' Default
  CP     = ScriptUnit.CodePageFromLangID(LangID)
  
  PEFileProxy.PostDebugString "Opening a file and checking resources..."

  if (PEFileProxy.OpenFileEx ("..\demo\src\demoapp1.exe", True)) then

    ResourcesProxy.SetLanguage LangID, DELETE_IF_EXISTS

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

    PEFileProxy.PostDebugString "Adding two more icons..."
    ResourcesProxy.ChangeIcon "1", LangID, CREATE_IF_NOT_EXIST, REPLACE_IF_ITEM_EXISTS,
 "..\demo\src\icon_3_32x32_8bit.ico"
    ResourcesProxy.ChangeIcon "1", LangID, CREATE_IF_NOT_EXIST, REPLACE_IF_ITEM_EXISTS,
 "..\demo\src\icon_4_16x16_32bit.ico"

    PEFileProxy.PostDebugString "Sorting out the icons..."
    ResourcesProxy.SortGroupIcon "", True

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

    PEFileProxy.PostDebugString "Saving file as a new file..."
    PEFileProxy.SaveAsNewImage "..\demo\release\demoapp1.exe"

    PEFileProxy.PostDebugString "Closing this file..."
    PEFileProxy.CloseFile

  else
    PEFileProxy.PostDebugString "Opening a file produced a fatal error."
  end if
  
end Sub
'------------------------------------------------------------------------------

RT Console outputs the Resource Tree to a log file, so you can see the changes made:

 
 Resource Tree built by Resource Tuner Console:
 ----------------------------------------------
 [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.

Start tuning your applications now

Resource Tuner Console offers exceptional value for money and delivers functionality that reaches far beyond its price tag. Discover how you and your organization can benefit from this exciting program. Start tuning your applications today!

Buy NowBuy Resource Tuner Console now for US$ 199, and make resource editing easier and faster.

Download a 30 day trial version of ResTuner     How to Order

     

Home  •   Site Map  •   Purchase  •   Downloads  •   Support  •   F.A.Q.  •   Forum  •   About