NetInverse Developers Blog

April 3, 2009
Category: WiX — Tags: , , , — admin @ 9:50 pm

We will use sample product.wxs file again in this example

  1. Create an xml file: product.wxs (copied from wix.chm)  as below
    This wix file will create an MSI file to copy readme.txt into %sysdrv%/program files/test program/

    <?xml version='1.0'?>
    <WiX xmlns='http://schemas.microsoft.com/wix/2003/01/wi'>
       <Product Id='12345678-1234-1234-1234-123456789012' Name='Test Package' Language='1033'
                Version='1.0.0.0' Manufacturer='Microsoft Corporation'>
          <Package Id='12345678-1234-1234-1234-123456789012'
                    Description='My first Windows Installer package'
                    Comments='This is my first attempt at creating a Windows Installer database'
                    Manufacturer='Microsoft Corporation' InstallerVersion='200' Compressed='yes' />
          <Media Id='1' Cabinet='product.cab' EmbedCab='yes' />
          <Directory Id='TARGETDIR' Name='SourceDir'>
             <Directory Id='ProgramFilesFolder' Name='PFiles'>
                <Directory Id='MyDir' Name='TestProg' LongName='Test Program'>
                   <Component Id='MyComponent' Guid='12345678-1234-1234-1234-123456789012'>
                      <File Id='readme' Name='readme.txt' DiskId='1' src='readme.txt' />
                   </Component>
                </Directory>
             </Directory>
          </Directory>
          <Feature Id='MyFeature' Title='My 1st Feature' Level='1'>
             <ComponentRef Id='MyComponent' />
          </Feature>
          <InstallExecuteSequence>
             <Custom Action="test" Sequence='1'/>
          </InstallExecuteSequence>
          <Binary Id='Customization.vbs' src='Customization.vbs'/>
          <CustomAction Id='test' BinaryKey='Customization.vbs' VBScriptCall='Hello' Return='check'/>
       </Product>
    </WiX>
  2. Create a customization VBS code: Customization.vbs
        function Hello
            msgbox Session.Property("MYPARAM")
        end function

    In the above VBS customization code, Session.Property is being used to retrieve to properties defined in your MSI. If the property MYPARAM is not defined in your wxs file, you can directly it as a command line parameter like below. MSI will automatically append it into its property list.

  3. Compile:
    c:wixcandle product.wxs
  4. Link:
    c:wixlight product.wixobj
  5. Test your MSI:
    c:wixmsiexec /i product.msi MYPARAM="WiX is cool."

    You will see the setup code pops up a dialog with the message “WiX is cool.”

  6. You can control when the CustomAction should be run by using attributes: Before, After or Sequence. For example:
         <InstallExecuteSequence>
             <Custom Action="test" After='InstallFinalize'/>    Note: "test" will run after "InstallFinalize"
          </InstallExecuteSequence>     
  7. You can also specify a condition for a custom action that should only be run at install or uninstall:
          $ComponentName > 2 Note: run at install
          $ComponentName = 2 Note: run at uninstall
         <InstallExecuteSequence>
             <Custom Action="test" After='InstallFinalize'><![CDATA[ $MyComponent > 2 ]]> </Custom>
          </InstallExecuteSequence>
         

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URL

Sorry, the comment form is closed at this time.

©2009 NetInverse. All rights reserved. Powered by WordPress