I have a requirement to call an exe which is stored in the binary table via a vbscript custom action,since my custom action runs before the installValide action and CopyFiles action. Hence, if I have the exe file in binary table I am thinking of calling the exe from there using vbscript custom action to get the return code and store it in a property using this vbscript.

1 Comment   [ - ] Hide Comment


  • I am using same kind of the logic. Now i have to extract 6 files. The Query specifies a single BinaryName to be extracted. But how to extract multiple binary files to temp. Could you please share your thoughts on the same.
Please log in to comment

Answer this question or Comment on this question for clarity



Here's an excerpt of code you can try.  I just streamed notepad.exe into the binary table, and gave it a name of 'notepad' as a test.  It's a quick example of extracting it to the %temp% folder and running it (note there is no cleanup etc).  One thing to remember though, is the session object isn't available in a deferred context.  So if you wanted (and probably should be) to run your exe in a deferred context then you may want to consider at what point in the sequence you extract and run your exe.

Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")

Dim tempFolder : tempFolder = oFSO.GetSpecialFolder(2) 
Dim outputFile : outputFile = tempFolder & "\notepad.exe" extractFromBinary "notepad", outputFile If oFSO.fileExists(outputFile) Then
 Dim objShell : Set objShell = CreateObject("WScript.Shell")
 objShell.Run (outputFile)
 Set objShell = Nothing
End If Function extractFromBinary(ByVal binaryName, ByVal binaryOutputFile)  Const msiReadStreamInteger = 0
 Const msiReadStreamBytes = 1
 Const msiReadStreamAnsi = 2
 Const msiReadStreamDirect = 3  Dim binaryView : Set binaryView = Session.Database.OpenView("SELECT * FROM Binary WHERE Name = '" & binaryName & "'")
 binaryView.Execute  Dim binaryRecord : Set binaryRecord = binaryView.Fetch
 Dim binaryData : binaryData = binaryRecord.ReadStream(2, binaryRecord.DataSize(2), msiReadStreamAnsi)
 Set binaryRecord = Nothing
 Dim binaryStream : Set binaryStream = oFSO.CreateTextFile(binaryOutputFile, True)
 binaryStream.Write binaryData
 Set binaryStream = Nothing 
End Function Set oFSO = Nothing
Answered 08/01/2013 by: captain_planet
Fourth Degree Brown Belt

  • It might be simpler to include the EXE in your package (maybe in %TEMP%, also) and, once your script has executed it, have the script delete it.
Please log in to comment