Programmatically add a file to an MSI

58 views
Skip to first unread message

Phlip

unread,
Aug 19, 2003, 10:56:15 PM8/19/03
to
Newsgroupies:

I have Googled relentlessly for this question, and have either found
short examples that don't show how to do it, or very long examples
that show how to build a complete MSI, in confusing detail.

Given an MSI file and a binary file (to become the installed
application's private data), how do I insert the binary into the MSI?

This may have something to do with MSI.DLL methods such as
OpenDatabase, OpenView, SetStream, Execute, CreateRecord, etc., right?

Thanks for any help finding the >simplest< complete example code
showing this one action!

--
Phlip
http://www.greencheese.org/HoneySatellite
-- It's a small Web, after all... --

Dennis Schmidt

unread,
Aug 20, 2003, 8:41:33 PM8/20/03
to
Hi Philip,

My name is Dennis Schmidt. Thank you for using the Microsoft Windows
Installer Newsgroups.

There is a sample vb script called WiImport.vbs that would get you started
in the right direction. You can get this example from the Platform SDK.

Microsoft Platform SDK (Includes Windows Installer)

http://www.microsoft.com/msdownload/platformsdk/sdkupdate/

I hope this helps! If you have additional questions on this topic, please
reply to this posting.

Need quick answers to questions like these? The Microsoft Knowledge Base
provides a wealth of information that you can use to troubleshoot a problem
or answer a question! It's located at
http://support.microsoft.com/support/c.asp?M=F>.

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2001 Microsoft Corporation. All rights
reserved.

Regards,
Dennis Schmidt
Microsoft Support

Phlip

unread,
Aug 21, 2003, 10:23:44 AM8/21/03
to
Dennis Schmidt wrote:

> There is a sample vb script called WiImport.vbs that would get you started
> in the right direction. You can get this example from the Platform SDK.

I can't figure out what it does. Its slim documentation did not state what
kind of file it imports. Let's try it. I'l pretend our customers need our
build script's log.txt file:

c:\phlip\>cscript WiImport.vbs MyApp_4_0.msi . log.txt
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Msi API Error 80004005: Import,Folder,File
1: 1314 2: .

Noope. Maybe it dislikes the dot. Try a target path:

c:\phlip\>cscript WiImport.vbs MyApp_4_0.msi [ProgramFilesFolder]\MyApp
log.txt
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Msi API Error 80004005: Import,Folder,File
1: 1314 2: [ProgramFilesFolder]\MyApp

Noope.

These problems are similar to the documentation for the database->Import()
method itself. They don't say what the "intent" of the function is, just a
hint at the meanings of the arguments.

Could you do me a favor and actually use WiImport.vbs to import a file
before replying?

--
Phlip
http://www.c2.com/cgi/wiki?TestFirstUserInterfaces


Dennis Bareis

unread,
Aug 21, 2003, 5:37:13 PM8/21/03
to
Hi,

On Thu, 21 Aug 2003 07:23:44 -0700, "Phlip" <phli...@yahoo.com>
wrote:

>Dennis Schmidt wrote:
>> There is a sample vb script called WiImport.vbs that would get you started
>> in the right direction. You can get this example from the Platform SDK.

>Could you do me a favor and actually use WiImport.vbs to import a file
>before replying?

I thik you'll find he meant that you can look at the code to get a
better idea of MSi manipulation rather than you should use it...

I don't know where this MSI comes from but if you were building the
whole thing (possibly easier) then I would have suggested my MAKEMSI
tool.

It could still be used but its "file" related commands should probably
be avoided (I haven't tried them in an MSI update rather than creation
situation). If you use the file table to simplify things make it
uncompressed and external so you can just copy the file to the
appropriate spot.

However for a single file Iyou might wish to add it to be binary table
and create a custom action to install it and possibly add it to the
"RemoveFile" table. All easy using MAKEMSI ("Binary" command and
perhaps the "VbsCA" command).


Bye,
Dennis.

----------------------------
Dennis Bareis (dba...@KillSpam.labyrinth.net.au)
http://www.labyrinth.net.au/~dbareis/index.htm

Free MSI automation/creation tool:
http://www.labyrinth.net.au/~dbareis/makemsi.htm
----------------------------

Phlip

unread,
Aug 21, 2003, 11:32:00 PM8/21/03
to
Note to Schmidt: Please don't consider this answered.

New question: I installed the latest PlatformSDK core and the Windows
Installer sub-kit. Where did the legendary ORCA.MSI go?

> I don't know where this MSI comes from but if you were building the
> whole thing (possibly easier) then I would have suggested my MAKEMSI
> tool.

I would rather insert the file into a freshly made MSI than tweak the VDPROJ
script that generated it.

At my site, there is the political issue of gaining mastery over MSIs
without proliferating tools.

Getting permission to use MAKEMSI will be easier if you can tell us that it
makes localization easier.

(BTW why did you zip an MSI?)

> However for a single file Iyou might wish to add it to be binary table
> and create a custom action to install it and possibly add it to the
> "RemoveFile" table. All easy using MAKEMSI ("Binary" command and
> perhaps the "VbsCA" command).

Given MyApp.msi, and file.txt, what would the command line look like to push
it in?

--
Phlip
http://www.c2.com/cgi/wiki?TestFirstUserInterfaces


Dennis Bareis

unread,
Aug 21, 2003, 11:48:51 PM8/21/03
to
Hi,

On Thu, 21 Aug 2003 20:32:00 -0700, "Phlip" <phli...@yahoo.com>
wrote:

>New question: I installed the latest PlatformSDK core and the Windows
>Installer sub-kit. Where did the legendary ORCA.MSI go?

It should have installed a "ORCA.MSI" which you need to install.


>> I don't know where this MSI comes from but if you were building the
>> whole thing (possibly easier) then I would have suggested my MAKEMSI
>> tool.
>
>I would rather insert the file into a freshly made MSI than tweak the VDPROJ
>script that generated it.
>
>At my site, there is the political issue of gaining mastery over MSIs
>without proliferating tools.
>
>Getting permission to use MAKEMSI will be easier if you can tell us that it
>makes localization easier.

It does not make it harder :-)
Given that everything can be scripted I would say the chances are very
good that it would be easier, I do however have no experience in this.


>(BTW why did you zip an MSI?)

I was playing it safe, I'm not sure all users would be set up to
handle it correctly (associations etc), plus I can guarantee that the
users have downloaded an uncorrupted version, a thing that amaziningly
Windows Installer does not try to confirm...

>> However for a single file Iyou might wish to add it to be binary table
>> and create a custom action to install it and possibly add it to the
>> "RemoveFile" table. All easy using MAKEMSI ("Binary" command and
>> perhaps the "VbsCA" command).
>
>Given MyApp.msi, and file.txt, what would the command line look like to push
>it in?


The script would look something like that at:


http://www.labyrinth.net.au/~dbareis/makemsi/making_changes_to_existing_databases.htm

But of course you are using the "Binary" command and some script to
pull it out at install time (there have been many recent posts on how
this can be done).

The command line would look the same or similar to that imbedded in
the "mm.cmd" batch file. Once set up the neither the command line or
script need vary.

Bye,
Dennis

Phlip

unread,
Aug 22, 2003, 8:10:48 AM8/22/03
to
> It should have installed a "ORCA.MSI" which you need to install.

My bad. The trick was searching for "ORCA.MSI" >after< I install the
platform SDK.

> >> However for a single file Iyou might wish to add it to be binary table
> >> and create a custom action to install it and possibly add it to the
> >> "RemoveFile" table. All easy using MAKEMSI ("Binary" command and
> >> perhaps the "VbsCA" command).
> >
> >Given MyApp.msi, and file.txt, what would the command line look like to
push
> >it in?
>
>
> The script would look something like that at:
>
>
>
http://www.labyrinth.net.au/~dbareis/makemsi/making_changes_to_existing_data
bases.htm
>
> But of course you are using the "Binary" command and some script to
> pull it out at install time (there have been many recent posts on how
> this can be done).
>
> The command line would look the same or similar to that imbedded in
> the "mm.cmd" batch file. Once set up the neither the command line or
> script need vary.

Dennis, you have noticed by now I am retarded.

The page you linked does not say how to add a file; it says how to change a
property.

What is the command, with MAKEMSI, or ORCA, or WiImport.vbs, to add a file?

--
Phlip


Dennis Bareis

unread,
Aug 25, 2003, 5:29:40 AM8/25/03
to
On Fri, 22 Aug 2003 05:10:48 -0700, "Phlip" <phli...@yahoo.com>
wrote:

>> The script would look something like that at:
>http://www.labyrinth.net.au/~dbareis/makemsi/making_changes_to_existing_databases.htm
>
>> But of course you are using the "Binary" command and some script to
>> pull it out at install time (there have been many recent posts on how
>> this can be done).
>>
>> The command line would look the same or similar to that imbedded in
>> the "mm.cmd" batch file. Once set up the neither the command line or
>> script need vary.
>
>Dennis, you have noticed by now I am retarded.
>
>The page you linked does not say how to add a file; it says how to change a
>property.
>
>What is the command, with MAKEMSI, or ORCA, or WiImport.vbs, to add a file?

The gist of it is adding a file to an MSI is not a simple thing. I
suggested MAKEMSI as a much easier alternative to adding the file via
"the API".

If you were building the MSI from scratch the file command could be as
simple as:

<$Files "AllFilesMatchingMask*.*">

To add a binary could be as simple as:

<$Binary "c:\dbareis\tools\where.exe">

The Custom action code to get a binary out is a bit more complicated.
I have created an example of how this is done, see:


http://www.labyrinth.net.au/~dbareis/makemsi/extract_binary_at_install_time.htm

Phlip

unread,
Aug 26, 2003, 10:59:30 PM8/26/03
to
Dennis Bareis wrote:

> The gist of it is adding a file to an MSI is not a simple thing. I
> suggested MAKEMSI as a much easier alternative to adding the file via
> "the API".
>
> If you were building the MSI from scratch the file command could be as
> simple as:
>
> <$Files "AllFilesMatchingMask*.*">

Thanks for trying to help, but...

Most thanks for confirming how impossible my quest is:

Here's the situation. I maintain the release scripts for a suite of
products. The same source can build different brands, flavors, versions, and
manifests. So I need a scripting solution on top of the MSI files that
narrows, not combinatorically explodes.

Imagine my surprise when I learned, very recently and by looking at kits
such as MAKEMSI, that devenv.exe (VS.NET) is not the only front-end to
MSI.DLL. >And< that devenv.exe does not even expose every feature!

So, part of recovering from this dismay was abandoning my attempt to
programmatically add product files to MSI files. Apologies for thinking they
could have been architected like sentient ZIP files.

This leaves me clinging to the current set of VDPROJ files - I don't want to
abandon all the existing ones that work.

So, here's my narrow technical solution to this situation: I wrote a parser
(using lean & robust Test Driven Development, natch) that converts VDPROJs
into in-memory data structures in C++. Now I manipulate those structures,
write back correct VDPROJ format, and feed this into devenv.exe.

So, essentially as a by-product of this effort, I can add files on the fly;
just before the MSI assembly process. This solution is sustainable for
uncomplicated MSIs; it meshes with my colleagues' abilities and development
environments, and I can run sanity checks on the MSIs before they go out the
door.

--
Phlip
http://www.c2.com/cgi/wiki?TestFirstUserInterfaces


Reply all
Reply to author
Forward
0 new messages