/build/static/layout/Breadcrumb_cap_w.png

Scripting Question


How to call an exe which is stored in a binary table through a vbscript custom action in the msi?

07/30/2013 6069 views

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   [ + ] Show comment

Comments

  • 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.

All Answers

1

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
 binaryStream.Close
 Set binaryStream = Nothing 
 
End Function Set oFSO = Nothing
Answered 08/01/2013 by: captain_planet
Black 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.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ