startseite
produkte
resource tuner console
beispiel-skripts
Demo-Skript: Zeichenfolgen bearbeiten, Versionsnummern aktualisieren, als Ressourcen-DLL speichern
Dieser Beispielcode demonstriert die Fähigkeiten von Resource Tuner Console. Er zeigt, wie Zeichenfolgen- und numerische Ressourcen in Windows-EXE- und DLL-Dateien mithilfe des Befehlszeilen-Ressourceneditors bearbeitet werden können.
Das Skript führt folgende Operationen an DemoApp1.exe aus:
- Bearbeitet Zeichenfolgen unter Verwendung von Zeichenfolgen- und numerischen Literalwerten aus der Definitiondatei
demoapp1.drcim Ordner "Defs". - Fügt eine neue StringTable hinzu und ändert die bestehende MessageTable.
- Aktualisiert die Versionsinformationen der ausführbaren Datei.
- Erstellt eine Kopie der Ressource (Message Table) in einer anderen Sprache.
- Gibt den Ressourcenbaum in einer Protokolldatei zur weiteren Analyse aus.
- Speichert schließlich alle Ressourcen der Datei als Ressourcen-DLL.
Die resultierenden Dateien werden im Verzeichnis "Release" gespeichert.
Für ausführliche Anweisungen zur Verwendung von Skripten mit Resource Tuner Console lesen Sie bitte die Schritt-für-Schritt-Anleitung zur Verwendung von Skripten.
Hinweis: Wenn Sie den Script-Code kopieren, stellen Sie bitte sicher, dass er keine Zeilenumbrüche enthält. Dies ist eine Anforderung von VBScript: der gesamte Befehl muss in einer Zeile stehen.
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 English-US
LangID = 1033 ' English-US
' Retrieve and output CodePage to log
CP = ScriptUnit.CodePageFromLangID(LangID)
PEFileProxy.PostDebugString "CodePage value for English-US: " & CStr(CP)
' Open file
PEFileProxy.PostDebugString "Open the file for editing..."
PEFileProxy.OpenFile ".\src\DemoApp1.exe"
if (PEFileProxy.Terminated) then
' Issue a warning in case of error
PEFileProxy.PostDebugString "Error when opening this file."
else
PEFileProxy.PostDebugString "File opened OK."
if (not PEFileProxy.HasResources) then
PEFileProxy.PostDebugString "The file contains no resources."
else
PEFileProxy.PostDebugString "The file contains resources."
' Zugriff auf eine externe Definitionsdatei, die die Werte
' für Konstanten enthält, die in der geladenen ausführbaren
' Datei verwendet werden.
PEFileProxy.ClearDefinitions
PEFileProxy.PostDebugString "Opening the definition file..."
PEFileProxy.OpenDefinitionFile ".\defs\demoapp1.drc"
' Edit strings in the StringTable
PEFileProxy.PostDebugString "Editing String Table..."
S1 = "My App Number1"
S2 = "Resource String: Item1 was modified."
S3 = "Resource String: Item2 was updated."
S4 = "Resource String: Item3 was changed."
S5 = "Version Info:"
S6 = "&Close App"
' Gain access to the entries using the definitions
ResourcesProxy.EditStringTable "dm1Unit_res_Caption", 0, CURRENT_LANG, S1, CP
ResourcesProxy.EditStringTable "dm1Unit_res_Label1", 0, CURRENT_LANG, S2, CP
ResourcesProxy.EditStringTable "dm1Unit_res_Label2", 0, CURRENT_LANG, S3, CP
ResourcesProxy.EditStringTable "dm1Unit_res_Label3", 0, CURRENT_LANG, S4, CP
ResourcesProxy.EditStringTable "dm1Unit_res_Version", 0, CURRENT_LANG, S5, CP
' Gain access to the entry using the entry index
ResourcesProxy.EditStringTable "65269", 0, CURRENT_LANG, S6, CP
' Create a new String Table (English-US)
S1 = "This resource has been added by RTC (English-US)"
ResourcesProxy.EditStringTable "1", 1033, CREATE_IF_NOT_EXIST, S1, CP
' Edit strings in the MessageTable
PEFileProxy.PostDebugString "Editing Message Table..."
S1 = "Event 1"
S2 = "Event 2"
S3 = "Event 5"
ResourcesProxy.EditMessageTable "1", 0, CREATE_IF_NOT_EXIST, 10001, S1, CP
ResourcesProxy.EditMessageTable "1", 0, CREATE_IF_NOT_EXIST, 10002, S2, CP
ResourcesProxy.EditMessageTable "1", 0, CREATE_IF_NOT_EXIST, 10005, S3, CP
S1 = "Error 1"
S2 = "Error 2"
ResourcesProxy.EditMessageTable "1", 0, CREATE_IF_NOT_EXIST, &H80000001, S1, CP
ResourcesProxy.EditMessageTable "1", 0, CREATE_IF_NOT_EXIST, &H80000002, S2, CP
S0 = "InsertItem 0"
S1 = "InsertItem 1"
S2 = "InsertItem 2"
ResourcesProxy.EditMessageTable "1", 0, CREATE_IF_NOT_EXIST, 10004, S1, CP
ResourcesProxy.EditMessageTable "1", 0, CREATE_IF_NOT_EXIST, 10000, S2, CP
ResourcesProxy.EditMessageTable "1", 0, CREATE_IF_NOT_EXIST, 0, S0, CP
S0 = "Negative value for ID"
ResourcesProxy.EditMessageTable "1", 0, CREATE_IF_NOT_EXIST, -1, S0, CP
' Open the Version Info for editing
PEFileProxy.PostDebugString "Open Version Info..."
if ResourcesProxy.OpenVersionInfo("1", 0, GET_DEFAULT_IF_NOT_EXIST) then
PEFileProxy.PostDebugString "Version Info opened."
' Output the current FileVersion & ProductVersion to a log file (optional)
PEFileProxy.PostDebugString "Current FileVersion: " &_
CStr(VersionInfoProxy.FileVersionMajor) & "." &_
CStr(VersionInfoProxy.FileVersionMinor) & "." &_
CStr(VersionInfoProxy.FileVersionRelease) & "." &_
CStr(VersionInfoProxy.FileVersionBuild)
PEFileProxy.PostDebugString "Current ProductVersion: " &_
CStr(VersionInfoProxy.ProductVersionMajor) & "." &_
CStr(VersionInfoProxy.ProductVersionMinor) & "." &_
CStr(VersionInfoProxy.ProductVersionRelease) & "." &_
CStr(VersionInfoProxy.ProductVersionBuild)
' Update FileVersion & ProductVersion numeric values
VersionInfoProxy.SetFileVersion 2, 1, 3, 1205, 1033, True, True, True
VersionInfoProxy.SetProductVersion 2, 0, 0, 0, 1033, True, True, True
' Output the updated FileVersion & ProductVersion to a log file (optional)
PEFileProxy.PostDebugString "Updated FileVersion: " &_
CStr(VersionInfoProxy.FileVersionMajor) & "." &_
CStr(VersionInfoProxy.FileVersionMinor) & "." &_
CStr(VersionInfoProxy.FileVersionRelease) & "." &_
CStr(VersionInfoProxy.FileVersionBuild)
PEFileProxy.PostDebugString "Updated ProductVersion: " &_
CStr(VersionInfoProxy.ProductVersionMajor) & "." &_
CStr(VersionInfoProxy.ProductVersionMinor) & "." &_
CStr(VersionInfoProxy.ProductVersionRelease) & "." &_
CStr(VersionInfoProxy.ProductVersionBuild)
' Set the file flags
VersionInfoProxy.FileFlagsMask = &H3F
VersionInfoProxy.FileFlags = VS_FF_PRERELEASE or VS_FF_PRIVATEBUILD
VersionInfoProxy.FileOS = VOS__WINDOWS32
VersionInfoProxy.FileType = VFT_DLL
VersionInfoProxy.FileSubType = VFT2_UNKNOWN
S1 = "Copyright \0xA9 2025 SuperSoftware Development"
S2 = "SuperProg is a trademark of SuperSoftware Development"
VersionInfoProxy.EditStringFileInfo "LegalCopyright", S1, CP, 1033, True, True
VersionInfoProxy.EditStringFileInfo "LegalTrademarks", S2, CP, 1033, True, True
S1 = "Dieser Eintrag wurde vom RTC-Demo-Skript hinzugefügt"
VersionInfoProxy.EditStringFileInfo "SpecialInfo", S1, CP, 1033, True, True
PEFileProxy.PostDebugString "Close the Version Info..."
ResourcesProxy.CloseVersionInfo
else
' Issue a warning in case of error
PEFileProxy.PostDebugString "Could not edit Version Information."
end if
' Compile all the changes made to the resources throughout the script
PEFileProxy.PostDebugString "Compiling all changes..."
PEFileProxy.Compile
' Create a copy of the resource (Message Table) with another language
PEFileProxy.PostDebugString "Creating a copy of the resource (Message Table)
with another language..."
PEFileProxy.PostDebugString "Copying Message Table:1 Neutral (0) to
Message Table:1 German-Swiss (2055)..."
ResourcesProxy.CopyResource RT_MESSAGETABLE, "1", 0, 2055
' Compile the changes again
PEFileProxy.Compile
' Build and output the Resource Tree to log to show all the changes made
PEFileProxy.PostDebugString ""
PEFileProxy.PostDebugString "Resource Tree built by RTC:"
ResourcesProxy.ResourceTreeToLog
PEFileProxy.PostDebugString ""
' Save operations
PEFileProxy.PostDebugString "Saving the file's resources as a resource DLL"
PEFileProxy.SaveAsResDll ".\release\demoapp1.res.dll"
PEFileProxy.PostDebugString "Saving the modified exe file..."
PEFileProxy.SaveAsNewImage ".\release\DemoApp1.exe"
end if
PEFileProxy.PostDebugString "Closing this file..."
PEFileProxy.CloseFile
end if
end Sub
Um die Änderungen, die man in Test-EXE-Dateien gemacht hat, zu sehen, empfehlen wir die Benutzung von Resource Tuner GUI, einem visuellen Ressourcen-Editor.
BEISPIEL-SKRIPTBIBLIOTHEK
Nach der Installation von Resorce Tuner Console finden Sie den Demo Scripts-Ordner im Verzeichnis, in dem RTC installiert wurde. In diesem Demo-Ordner befinden sich 12 Unterverzeichnisse mit Skriptbeispielen und Beispieldateien.
Alle Beispielskripte sind einsatzbereit. Wählen Sie eine der .BAT-Dateien in den Demo Scripts-Ordnern aus, um das Beispielskript auszuführen. Das Skript wird Änderungen in der Test-EXE-Datei vornehmen. Die resultierende Datei wird im Verzeichnis Release unter dem Verzeichnis erstellt, das das Skript enthält.
Schritt-für-Schritt Anleitung wie man Skripte benutzt
Laden Sie Resource Tuner Console herunter und erfahren Sie, wie es Ihre Produktivität steigern kann.