Heaventools

   English English  Deutsch Deutsch

Add or Replace an UAC Manifest for Vista User Access Control

This code shows the way you can edit or add a manifest to the compiled executable file. You can specify whether to replace the existing manifest, or add a new manifest resource to the executable file that doesn't have one.

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 an application manifest to the DemoApp1.exe file, then add 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.

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 XML Manifest

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
  
  'Set Language to default value
  LangID = 0 
  
  'Retrieve and output CodePage to log
  CodePage = ScriptUnit.CodePageFromLangID(LangID)
  PEFileProxy.PostDebugString "CodePage value for English-US: " & CStr(CodePage)

  '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

    'Add XML Manifest

    PEFileProxy.PostDebugString "Add/edit XML Manifest..."
    ResourcesProxy.ChangeManifest EXE_MANIFEST, LangID, CREATE_IF_NOT_EXIST, 
".\demo\src\exe_manifest.xml"

'-------- Optional operations: Add or Replace Icons (for demo purpose) --------------

    PEFileProxy.PostDebugString "Change/add the full Vista icon set (10 icons)..."
    ResourcesProxy.ChangeIcon "", LangID, CREATE_IF_NOT_EXIST, REPLACE_IF_ITEM_EXISTS, 
".\demo\src\vista_iconset.ico"

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

    'Build and output the Resource Tree to show the changes made to the resources

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

    'Save and close file
    PEFileProxy.PostDebugString "Saving file as a new file..."
    PEFileProxy.SaveAsNewImage ".\demo\release\DemoApp1.exe"

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

  Else
    'Issue a warning in case of error
    PEFileProxy.PostDebugString "Error when opening this file."
  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 nested in the directory where RTC has been installed. Within this Demo folder, there are 12 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.

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