Resource Tuner Console
'------------------------------------------------------------------------------
' RTC http://www.heaventools.com
'
' This sample VBScript code provides a real-world example that demonstrates
' many of the features available in Resource Tuner Console.
'
' This code shows how to modify icons in executables with Resource Tuner Console.
'
' The script will add or replace icons in demoapp1.exe with icons from .ico
' files resided 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.
'
' Resource Tuner Console Demo allows you to process only two files at a time. 
' Register to remove this limitation.
'
'------------------------------------------------------------------------------

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
'------------------------------------------------------------------------------