English English  Deutsch Deutsch

home  products  resource tuner console  sample scripts library

Add or Replace an UAC Manifest for Windows User Access Control

This code shows the way you can edit or add a manifest to a compiled executable file.

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:
'   - replace icons in the executable with icons from an .ico file which 
'     contains more than one image.

'   - sort out the added icons in the right order
'   - add or replace an UAC manifest
'   - output the changes in the Resource Tree to a log file.
' To give you an idea of how this all works, we made this sample script and
' test application. When you installed Resorce Tuner Console on your computer,
' the setup program created the "Demo" folder under the RTC folder, with 
' the test application "DemoApp1.exe" in the "\Demo\Src" folder. 
' The script will add or replace icons in demoapp1.exe with icons from the .ico
' and .png files from the "\Demo\Src" folder. 
' The resulting file will be created in the directory named "\Demo\Release"
' Check the log file "rtc.log" to see the Resource Tree changed.  
' Demonstrates the following:
' - PEFileProxy.OpenFileEx
' - PEFileProxy.Terminated
' - PEFileProxy.HasResources
' - PEFileProxy.CreateBackUp
' - PEFileProxy.SaveAsNewImage
' - PEFileProxy.PostDebugString
' - PEFileProxy.UpdateCheckSum
' - ResourcesProxy.ChangeIcon
' - ResourcesProxy.ChangeVistaIcon
' - ResourcesProxy.ChangeManifest
' - ResourcesProxy.SetLanguage
' - ResourcesProxy.SortGroupIcon
' - ResourcesProxy.ResourceTreeToLog
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..."

  'Open file
  'Once the file is opened successfully, check if the file contains resources
  'If not, create resources

  If (PEFileProxy.OpenFileEx (".\demo\src\DemoApp1.exe", True)) Then

    ResourcesProxy.SetLanguage LangID, DELETE_IF_EXISTS

PEFileProxy.PostDebugString "Changing/adding the full Vista icon set (10 icons)..."

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

'Edit XML Manifest

    PEFileProxy.PostDebugString "Adding/editing XML Manifest..."
    ResourcesProxy.ChangeManifest EXE_MANIFEST, LangID, CREATE_IF_NOT_EXIST, 

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

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

    PEFileProxy.PostDebugString "Closing this file..."

    PEFileProxy.PostDebugString "Opening a file produced a fatal error."
  End If

End Sub

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.