Hello and thanks for having such great information!
Recently I was looking at your article “Write to the Windows Installer Binary Stream using Powershell” and was wondering if you possibly had an example of writing to the ‘CustomAction’ table to run embedded code (like VBScript)? Meaning, that the ‘Target’ contains the VBS code (not a file) and the value is read from a file.
I have been able to produce this with VBS (Microsoft’s “WiTextIn.vbs”); but not in PowerShell.
TIA for any guidance.
- You must login to post comments
This example should get you started: https://www.alkanesolutions.co.uk/2020/06/25/insert-a-vbscript-custom-action-into-a-windows-installer/
There are a few types of VBscript custom action – the most popular two being either to stream your VBS into the binary table and run it from there, or alternatively to write your actual VBScript code into the Target column.
In the latter type of Custom Action (type 38) if you wanted to read content from an external file to populate your custom action you could simply replace
$vbscriptCode = "Msgbox('hello')`r`nMsgbox('again')" with
$vbscriptCode = [IO.File]::ReadAllText("C:\Apps\AlkaneFile.txt").
- Updated my answer…
- Thanks for the update, however when testing I am getting the following right after – $View.GetType().InvokeMember(“Execute”, “InvokeMethod”, $Null, $View, $binaryrecord) : Exception calling “InvokeMember” with “5” argument(s): “Execute,Params” At line:1 char:1 + $View.GetType().InvokeMember(“Execute”, “InvokeMethod”, $Null, $View, … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) , MethodInvocationException + FullyQualifiedErrorId : COMException
- Remember there is no error handling in the script as such. If you already have a custom action of the same name, you will likely see an error like that…
- By George you are correct! Tested against a backup MSI and a different MSI, with success on both. I will circle back and add handling for if CustomAction exists as well as setting ‘InstallExecuteSequence’. Thank you so much for all your help in this.
- You’re welcome!
Please login first to submit.