working with features

Upload: mikra10

Post on 02-Jun-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 Working With Features

    1/32

    Working with Features 1

    Working with Features

    In this topic

    Fundamentals of features.

    Tying the installation of one feature to another feature.

    Selecting features using serial numbers.

    Tying the installation of a component to the install state of another feature.

    The feature tree of a product is characterized as being the end users view of your product.It is through the selection of features to be installed that the associated componentsactually get installed to the target machine. Many setup developers do not want to use thestandard SelectionTree control and allow the end user to select the features to beinstalled. To by-pass the use of the SelectionTree control and to select the features to beinstalled for the end user requires the use of programmatic means. The programmaticcontrol of features is the main focus of this topic.

    Feature fundamentalsThe ultimate aim of software installation is to install files in such a manner that theapplication runs correctly after the installation is complete. file is one of the ma!orresources that is used to define components and components are used to define features."hen you select a feature to be installed you are determining which components will beinstalled and thus which files are actually involved. #ou can e$ert control over whichfeatures get installed by authoring the %ondition table. #ou can also place a condition ona component using the %ondition column of the %omponent table and thus controlcomponents individually.

    The database tables that come into play with regard to which files get installed when youselect certain features for installation are shown in the entity relationship diagram inFigure &.

    Note

    The format for entity relationship diagrams used in this and other topicsshows the name of the columns in the indicated table with the data typefollowing the name and then an indicator if the column can be NULL ornot. N means that the column cannot be NULL and Y means that thecolumn can be NULL. The column names that are shown in the upper boare the ones that form the primary !ey for the table. If there is only onebo then all columns define the primary !ey. The relationship betweentables is as shown in the diagram below"

    The Official InstallShield Professional Windows Installer EditionDevelo er!s "uide

    #ne to $any %elationship

  • 8/11/2019 Working With Features

    2/32

    Working with Features #

    Feature& 'Identifier( N)omponent& 'Identifier( N

    Feature$o% onents Ta&le

    )omponentI* '+UI*( Y*irectory& 'Identifier( N

    ,ttributes 'Integer( N)ondition ')ondition( Y-ey ath 'Identifier( Y

    )omponent 'Identifier( N

    $o% onent Ta&le

    )omponent& 'Identifier( NFileName 'Filename( NFile/i0e '*oubleInteger( N1ersion '1ersion( YLanguage 'Language( Y

    ,ttributes 'Integer( Y/e2uence 'Integer( N

    File 'Identifier( N

    File Ta&le

    Feature& arent 'Identifier( YTitle 'Te t( Y*escription 'Te t( Y*isplay 'Integer( YLe3el 'Integer( N*irectory& 'Identifier( Y

    ,ttributes 'Integer( N

    Feature 'Identifier( N

    Feature Ta&le

    )ondition ')ondition( Y

    Feature& 'Identifier( NLe3el 'Integer( N

    $ondition Ta&le

    *irectory& arent 'Identifier( Y*efault*ir '*efault*ir( N

    *irectory 'Identifier( N

    Director' Ta&le

    Figure 1The entity relationship diagram for the database tables that control theinstallation of files

    #ou define the logical structure of an application by identifying the features of the

    application in the Feature table. To get the necessary files installed you then definecomponents in the %omponent table that contain these files and other necessaryresources. #ou then associate your components with the features through the use of theFeature%omponents table. #ou need this additional table because there can be a many-to-many relationship between features and components. ll the files that ma'e up yourapplication are listed in the File table. For each file listed in this table there is a referenceto the component that contains the file as a resource.

    The Official InstallShield Professional Windows Installer EditionDevelo er!s "uide

  • 8/11/2019 Working With Features

    3/32

    Working with Features (

    (oth the Feature table and the %omponent table are connected to the )irectory table. The)irectory* column in the Feature table contains the name of a directory that can beconfigured by a browse dialog. +ormally you will ma'e this the name of a public

    property since only public properties can have their values set from the user interface.The )irectory* column of the %omponent table is the name of a property that contains

    the complete path to where the associated files are to be installed. #ou should not ma'ethis location one of the ,ser rofile folders since not all users will have access privilegesto these folders and thus under certain circumstances the "indows Installer wouldconsider the component as always needing repair after it was installed. It is interesting tonote from Figure & that a feature does not need to have a directory specified but acomponent does need to specify an installation location. "hen a directory is not definedfor a feature it means that the end user will not have the capability to browse for a folderand thus the files will be copied to where the component destination has been defined.This would be totally satisfactory if all components are be copied to an S definedlocation such as the System/0 folder.

    File costing and its i% act on features and co% onents"hen you place conditions on a feature those conditions are placed in the %onditiontable. (ased on a condition you can modify the install level of a feature that has beenauthored into the Feature table. The conditions that you can place on a component controlwhether a component is installed or not1 they are not used to set another attribute as isdone with conditions on a feature. The conditions that are contained in the %onditiontable and in the %ondition column of the %omponent table are evaluated when the%ostFinalize action is e$ecuted. These conditions are evaluated before the installed statesof any feature or component are evaluated. (ecause of this you cannot use the installedstate of any feature or component in the conditional e$pressions that you enter into thesetables. I tal' more about feature and component states in the 2Feature and componentstates3 section below.

    )uring the file costing operation a number of temporary columns are added to theFeature1 %omponent1 File1 and )irectory tables. For the Feature table the "indowsInstaller adds nine temporary columns1 for the %omponent table fourteen temporarycolumns are added1 the File table gets two temporary columns and the )irectory tablegets four temporary columns. These temporary columns are used both to calculate thecost of the installation as well as the states of both features and components. "hen time

    permits I will put up on the "eb site the code and the pro!ect that I used to discover thisinformation.

    Sharing co% onents &etween features

    Features can share components and this sharing can be a common scenario. It is possiblefor you to run a maintenance operation where you uninstall a feature while leaving otherfeatures on the target machine that are all sharing the same component. (ecause of thisthe "indows Installer has to have a means to reference count not only the products thatare using a component but the features of a particular product that are sharing

    The Official InstallShield Professional Windows Installer EditionDevelo er!s "uide

  • 8/11/2019 Working With Features

    4/32

    Working with Features )

    components. %omponents are reference counted based on the features that are using themunder the following registry 'ey4

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Inst!""er\Fe!tures\#$!c%ed $roduct &'I(s)

    5very product that has installed a feature to either run locally or to run-from-source willhave an entry or entries under the pac'ed roduct %ode for the product. The value nameswill be the names of the features that have been installed and the value data will be theconcatenated compressed component 6,I)s for all the components that are associatedwith the feature. If the feature has a parent feature then the name of the parent will beappended to this list of compressed component 6,I)s with the 78$09 character beingused as a delimiter.

    $aution

    ,s I ha3e done in the boo!4 I need to warn you that the abo3e informationabout how the 5indows Installer uses the registry is only applicable to

    3ersions 6.74 6.64 and 6.8 of the 5indows Installer. The ne t 3ersion of the5indows Installer will most li!ely change how it uses the registry. Thisinformation is presented only so that you can see the basic approach thatis used to store information about the products that are being installed.

    Feature and co% onent states

    Features and components have two types of states1 action states and installed states. Theaction state of a feature defines what is going to happen to the feature during aninstallation or a maintenance operation. The installed state of a feature defines what hashappened to it during an installation or during a maintenance operation. The installedstate of a feature is entered into the registry so that when you run a maintenanceinstallation on an installed product it is possible for the "indows Installer to 'now whatfeatures have been installed locally1 run-from-source1 advertised1 or not installed. Forversions &.81 &.&1 and &.0 of the "indows Installer this information is written in one oftwo locations depending on whether the install was originally performed for the currentuser or for the machine. "hen an installation is performed for the current user the featureinstalled state is written to the following registry 'ey4

    HKEY_C'RRENT_'SER\SOFTWARE\Microsoft\Inst!""er\Fe!tures

    ,nder this 'ey are sub-'eys that consist of the pac'ed product codes for all productsinstalled per-user. ,nder each of these sub-'eys are value names equal to the featurenames and the value data is the name of the feature9s parent. The value data is preceded

    by a special to'en if the feature was not installed. This to'en is called the (S5+Tto'en. For a per-machine install this information is written to the following location4

    HKEY_LOCAL_MACHINE\SOFTWARE\C"!sses\Inst!""er\Fe!tures

    The "indows Installer combines this information with the information written in other places in the registry to determine the actual state of each feature when you perform amaintenance operation.

    The Official InstallShield Professional Windows Installer EditionDevelo er!s "uide

  • 8/11/2019 Working With Features

    5/32

    Working with Features *

    There are a number of states that a feature or component can have and these are shown inTable &.

    Ta&le 1The +ction and Installed States for Features and $o% onents

    State $onstant ,alue Descri tion

    I+ST ::STT5*+ T,S5) -; This state applies only to componentsand it means that the component isdisabled.

    I+ST ::STT5*( )% +FI6 -< This means that the configuration datain the registry has been corrupted.

    I+ST ::STT5*I+% M :5T5 -= This means that the installation has been resumed after an interruption orhas been suspended for some reason or

    another. This does not apply to theaction state of a feature or component.

    I+ST ::STT5*S ,>%5 (S5+T -? This means that a run from sourcefeature or component is not available

    because the source is not present.

    I+ST ::STT5*M >5) T -/ This indicates that the return buffer isfull.

    I+ST ::STT5*I+@:I) >6 -0 This means that an invalid argumentwas passed to the function.

    I+ST ::STT5*,+A+ "+ -& This means that the "indows Installerwill not be ta'ing any action on thefeature or component name that was

    passed to the function. This will be thereturn value for the action state of afeature or component that by default isnot to be installed during a first timeinstall. It will also be the return valuefor a feature where no action is beingta'en during a maintenance operation.

    I+ST ::STT5*(> A5+ 8 This means that the "idows Installer

    sees the feature or component as being bro'en.

    I+ST ::STT5* )@5>TIS5) & This value is only applicable tofeatures since components cannot beadvertised. This state constant can beused to retrieve or to set the state of afeature.

    The Official InstallShield Professional Windows Installer EditionDevelo er!s "uide

  • 8/11/2019 Working With Features

    6/32

    Working with Features -

    State $onstant ,alue Descri tion

    I+ST ::STT5*>5M @5) & This value is applicable only tocomponents and it indicates an actionstate for a component that is beinguninstalled. This state constant cannot

    be used to set the state of a component.I+ST ::STT5* (S5+T 0 This value indicates that a feature or a

    component is not installed or that ithas been uninstalled.

    I+ST ::STT5*: % : / This value indicates that a feature or acomponent will be or has beeninstalled to the local machine.

    I+ST ::STT5*S ,>%5 ? This value indicates that a feature or acomponent will be or has beeninstalled to run from source.

    I+ST ::STT5*)5F ,:T = This value indicates that a feature or acomponent is being installed in thedefault state.

    The state constants shown in Table & come from the I+ST::STT5 enum typedef thatis defined in the MSI.B header file. The states that are important to the code e$amplesthat are described in this topic are the ones that I have shaded in Table &.

    .ow the service rocess knows how to handle features

    "hen the end user selects or deselects features in the %ustomSetup dialog there needs to be some means of letting the service process 'now what changes have been made in thedefault selection. n "indows +T and "indows 0888 this can only be done through theuse of public properties. The particular public properties that are of interest to us areshown in Table 0. lso1 because they are public properties they can be set on thecommand line. If these properties are used on the command line the "indows Installerwill set the reselected property to a value of &. ,sing this property it is possible tomodify the user interface sequence so that the %ustomSetup dialog will not be availableto the end user. This is a valid scenario since you probably do not want the end user tomodify the selection of features to be installed if they are being preselected on thecommand line.

    Ta&le #Feature Selection Pu&lic Pro erties

    Pro ert' Na%e Descri tion

    )): % : This property is a comma-delimited list of feature namesthat are to be installed to run locally. This property canalso be set to the value of :: and this will then include

    The Official InstallShield Professional Windows Installer EditionDevelo er!s "uide

  • 8/11/2019 Working With Features

    7/32

    Working with Features /

    Pro ert' Na%e Descri tion

    all features in the product. If this property is not set onthe command line then the 5$ecute ction action willcreate this property when it is e$ecuted at the end of theInstall,ISequence table and there are features that theend user has selected to be installed locally.

    >5M @5 This property comes into play when performing amaintenance operation. This property is a comma-delimited list of feature names that are to be removedfrom the system. It can also be set to a value of :: andthis will mean that all features are to be included. If this

    property is not set on the command line then the5$ecute ction action will create this property when it ise$ecuted at the end of the Install,ISequence table andthere are features that the end user has selected toremove. This property will get set to the value of ::during an uninstallation.

    ))S ,>%5 This property is a comma-delimited list of feature namesthat are to be installed to run from source. This propertycan also be set to the value of :: and this will theninclude all features in the product. If this property is notset on the command line then the 5$ecute ction actionwill create this property when it is e$ecuted at the end ofthe Install,ISequence table and there are features that theend user has selected to be run from source.

    )))5F ,:T This property is a comma-delimited list of feature namesthat are to be installed in their default state. This propertycan also be set to the value of :: and this will theninclude all features in the product. This property is onlyusable from the command line. "hen using this propertyon the command line the 5$ecute ction action will createthe )): % :1 ))S ,>%51 and the )@5>TIS5

    properties according to the default states for the featuresin the product. ll feature names that are not listed as thevalue of this property are not installed.

    >5I+ST :: This property is a comma-delimited list of feature names

    that are to be reinstalled. This property can also be set tothe value of :: and this will then include all features inthe product that have already been installed. This

    property is set during a repair maintenance operation andit is also used on the command line when performing asmall update or a minor upgrade.

    )@5>TIS5 This property is a comma-delimited list of feature namesthat are to be advertised. This property can also be set to

    The Official InstallShield Professional Windows Installer EditionDevelo er!s "uide

  • 8/11/2019 Working With Features

    8/32

    Working with Features 0

    Pro ert' Na%e Descri tion

    the value of :: and this will then include all features inthe product. If this property is not set on the commandline then the 5$ecute ction action will create this

    property when it is e$ecuted at the end of theInstall,ISequence table and there are features that theend user has selected to be advertised.

    % M )): % : This property is a comma-delimited list of componentcodes C6,I)sD that are to be installed locally. This

    property is used at the command line to force theinstallation of the feature containing this component. Ifthis component is shared among several features then thefeature that will be installed is the one that requires theleast space on the target machine. If the component forwhich the component code is listed has been set in the%omponent table as being Source nly then thecomponent will be installed to run from source and not torun locally. For the component to be installed to runlocally the attribute flag :ocal nly or ptional needs to

    be set in the %omponent table.

    % M ))S ,>%5 This property is a comma-delimited list of componentcodes C6,I)sD that are to be installed to run from source.This property is used at the command line to force theinstallation of the feature containing this component. Ifthis component is shared among several features then thefeature that will be installed is the one that requires the

    least space on the target machine. If the component forwhich the component code is listed has been set in the%omponent table as being :ocal nly then the componentwill be installed to run locally and not to run from source.For the component to be installed to run from source theattribute flag Source nly or ptional needs to be set inthe %omponent table.

    FI:5 )): % : This property is a comma-delimited list of File table 'eysfor files that are to be installed to run locally. This

    property is used at the command line to force theinstallation of the feature containing the component thatinstalls the identified file. The "indows Installer loo'sfor the component that is installing a listed file and thenloo's for the feature that needs to be installed in order toget the component installed. If more than one feature issharing the component the feature that will be installed isthe one that ta'es the least space on the target machine. If the component for which the component code is listedhas been set in the %omponent table as being Source nly

    The Official InstallShield Professional Windows Installer EditionDevelo er!s "uide

  • 8/11/2019 Working With Features

    9/32

    Working with Features

    Pro ert' Na%e Descri tion

    then the component will be installed to run from sourceand not to run locally. For the component to be installedto run locally the attribute flag :ocal nly or ptionalneeds to be set in the %omponent table.

    FI:5 ))S ,>%5 This property is a comma-delimited list of File table 'eysfor files that are to be installed to run from source. This

    property is used at the command line to force theinstallation of the feature containing the component thatinstalls the identified file. The "indows Installer loo'sfor the component that is installing a listed file and thenloo's for the feature that needs to be installed in order toget the component installed. If more than one feature issharing the component the feature that will be installed isthe one that ta'es the least space on the target machine. If the component for which the component code is listedhas been set in the %omponent table as being :ocal nlythen the component will be installed to run from sourceand not to run locally. For the component to be installedto run from source the attribute flag Source nly orptional needs to be set in the %omponent table.

    FI:5 )))5F ,:T This property is a comma-delimited list of File table 'eysfor files that are to be installed in the default state of thecomponents that contain them. The "indows Installerloo's for the component that is installing a listed file andthen loo's for the feature that needs to be installed in

    order to get the component installed. If more than onefeature is sharing the component the feature that will beinstalled is the one that ta'es the least space on the targetmachine.

    The properties in Table 0 are evaluated by the "indows Installer in the order they areshown in the table. "hat this means is that a property that is evaluated later can overridethe setting of a property that is evaluated earlier. To use the e$ample shown in the"indows Installer help assume the following scenario4 at the command line you specify)): % :E :: ))S ,>%5EFeature&. This will first set all features to beinstalled to run locally and then it will change Feature& so that it is installed to run from

    source. This is because the )): % : property is evaluated before the ))S ,>%5 property. This scenario will only be possible if Feature& has been configured so that it can be installed either locally or to run from source. feature will only have both possibilitiesif the associated components have the ptional attribute set or there is a mi$ture ofcomponents where some of the components have the :ocal nly attribute set and othercomponents have the Source nly attribute set. If a feature contains components where allthe components have the :ocal nly attribute set then the feature will not have the

    possibility of being installed to run from source.

    The Official InstallShield Professional Windows Installer EditionDevelo er!s "uide

  • 8/11/2019 Working With Features

    10/32

    Working with Features 12

    + lica&le Windows Installer +PIs

    For wor'ing with feature states there are two functions that are available from the"indows Installer. These functions are Msi6etFeatureStateCD and MsiSetFeatureStateCD."e will use these two functions in the e$amples that are described in the ne$t section.First let9s ta'e a brief loo' at these two functions.UINT MsiGetFeatureState(

    MSIHANDLE hInstall , ** +!nd"e to t+e inst!"" sessionLPCTSTR szFeature , ** n!-e of fe!tureINSTALLSTATE . piInstalled , ** returned /!"ue of

    ** inst!""ed st!teINSTALLSTATE . piAction ** returned /!"ue of !ction st!te

    )

    The possible return values for both the installed sate and the action state are listed inTable &. The piInstalled argument returns the installed state of the specified feature if the feature has already been installed. The piAction argument returns the action state of the specified feature. This is the state to which it is changing during the installation.UINT MsiSetFeatureState(

    MSIHANDLE hInstall , ** +!nd"e to t+e inst!"" sessionLPCTSTR szFeature , ** n!-e of fe!tureINSTALLSTATE iState , ** st!te to set

    )

    ,sing this function you can change the selected state of a feature. The possibilities hereare to set the states to I+ST ::ST T5* (S5+T1 I+ST ::ST T5*: % :1I+ST ::STT5*S ,>%51 or I+ST ::STT5* )@5>TIS5).

    There are two functions Msi6et%omponentStateCD and MsiSet%omponentStateCD that perform the same operation on components that above described functions perform onfeatures. These to Is are not described here since the e$amples do not use thesefunctions.

    9 ample scenariosTa'ing the information that is presented above I want to discuss how you might applythis information to the control of features during an installation. I will do this through theuse of a number of different e$amples. The e$amples that I will use are described in thefollowing list4

    Tying the installation state of one feature to the install state of another feature by manipulating the value of the )): % : and >5M @5 properties.

    Tying the installation state of one feature to the install state of another feature by using the Msi6etFeatureStateCD and MsiSetFeatureStateCD functions.

    The Official InstallShield Professional Windows Installer EditionDevelo er!s "uide

  • 8/11/2019 Working With Features

    11/32

    Working with Features 11

    %ontrolling the selection of features using a serial number. This will be performed after file costing has been performed and as such the end user willnot have the option to deselect any of the available features.

    %ontrolling the selection of features using a serial number. This will be

    performed prior to file costing so that the end user will be able to deselectsome or all of the available features.

    Tying the installation of a component to the install state of a feature.

    To implement the above listed scenarios you will be using custom actions. "hen youcreate these custom actions they will be using functions e$ported from a dynamic-lin'library that you can create from the code shown in the following description of the listedscenarios. The complete source code and compiled ):: is also available for download.#ou need to ma'e these custom actions synchronous1 immediate custom actions and youshould set their properties so that they will always e$ecute and so that the "indows

    Installer will not ignore the return value."hen you create custom actions to control the install state of a feature you need toremember that you need to be able to handle not only a new installation but also amaintenance operation and the situation where the features to be installed have beenidentified on the command line.

    Download ackage

    There is a pac'age that you can download in the form of a self-e$tracting e$ecutable.This pac'age contains a template pro!ect that can be used as the starting point to createthe other pro!ects that implement the above listed scenarios. lso included are the four

    pro!ects that implement the various scenarios. These four pro!ects are named Features&1Features01 Features/1 and Features?. s part of the download pac'age are the source filesthat ma'e up the installation. These files are 8-byte files that are used !ust to verify theinstallation of a component. lso included is the source code for the ):: thatimplements the various custom actions used in the five scenarios. The default location for installing the files in the download pac'age is as follows4

    C0\Wor%in1 wit+ Fe!tures

    If you accept this default location then you can open any of the pro!ects in version 0.8& of InstallShield rofessional "indows Installer 5dition and build the pro!ects immediatelywithout having to worry about fi$ing the file lin's. lso the @isual %GG pro!ect contains a

    ost-(uild command that copies the ):: to the custom action source location every timethat you build it. If you install the download pac'age to another location you will have tofi$ the path variables in each of the pro!ects and you will have to modify the ost-(uildcommand in the @isual %GG pro!ect to be compatible with the new location.

    s already mentioned I have also included a template C.istD pro!ect that defines the basicstructure of the application that is used to demonstrate how to control features

    programmatically. The name of this file is (asicFeature%ontrol.ist and it defines nine

    The Official InstallShield Professional Windows Installer EditionDevelo er!s "uide

  • 8/11/2019 Working With Features

    12/32

    Working with Features 1#

    features each with three components. The naming convention used for the features isFeatureH where H goes from & through . The naming convention used for thecomponents is FH%# where H stands for the number of the feature and # standscomponent number. For e$ample1 the third component under Feature0 would have thename F0%/.

    For the sa'e of simplicity in the demonstrating of the techniques of controlling featuresthe attributes for features are such that in the %ustomSetup dialog there are only theoptions to install the feature to the local hard drive or to not install the feature at all. Thisis accomplished by setting the dvertisement property for each feature to 2)isallowdvertise3 and for each component setting the >emote Installation property to 2Favor:ocal3. lso1 so that we can easily see which features have been installed and which havenot each component has been give a subfolder name under I+ST ::)I> that is the samename as the feature to which it belongs. For e$ample1 the )estination property forcomponent F&%/ is JI+ST ::)I>KLFeature&. This ma'es it easy for you to loo' at theinstallation location and see if the manipulation of features wor'ed as desired. The four

    pro!ects that are used to implement the five scenarios are modifications of this basic pro!ect template. +ow lets ta'e a close loo' at the five scenarios and see the variousmethods you can use to manipulate features at run time.

    3ani ulating the +DD4O$+4 and 5E3O,E ro erties

    Table 0 described a number of public properties that can be used to control what featuresget installed on the target machine. In this scenario you will be seeing how to use two ofthese properties to tie two features together so that only one of the features will ever beinstalled at any given time. Manipulating these properties is probably not what you wantto do since the ne$t scenario describes a simpler approach to this type of control.Bowever1 the present scenario does provide an e$ercise that ma'es it moreunderstandable how the "indows Installer uses some of these properties.

    In this scenario you only have to be concerned about the )): % : and the >5M @5 properties since the pro!ect that we are using only allows for a feature to be installedlocally or to not be installed. The basic premise here is that we want to tie Feature/ andFeature? together so that only one of these features is ever installed at any one time. Thesteps that we need to ta'e in creating the Features& pro!ect from our template pro!ect arelisted as follows4

    &. In InstallShield rofessional "indows Installer 5dition create a pro!ect namedFeatures& using the (asicFeature%ontrol.ist template file.

    0. For Feature? set the Install :evel property to &8& so that this feature will notautomatically get installed by default.

    /. For Feature? set the )isplay property to +ot @isible. This is because we do notwant the end user to be able to select it in the %ustomSetup dialog. It is not

    possible in the SelectionTree control to have a feature selection state tied to theselection state of another feature.

    The Official InstallShield Professional Windows Installer EditionDevelo er!s "uide

  • 8/11/2019 Working With Features

    13/32

    Working with Features 1(

    ?. %reate an immediate "indows Installer ):: custom action that has theSetFeatureFour e$ported function as the target. good approach is to name yourcustom action the same as the name of the e$ported function.

    =. Insert the custom action in item ? into the Install5$ecuteSequence table right after

    the :aunch%onditions standard action.The implementation of the custom action that manipulates the )): % : and>5M @5 properties is shown below. 5ven though we do not have to worry about havinga feature installed to run from source we do have to be concerned with the end userchanging the feature selection on the command line by setting the I+ST:::5@5:

    property so that both Feature/ and Feature? will get installed during a first timeinstallation. "hen we find that both Feature/ and Feature? are both being installed weneed to ta'e action in the code so that Feature? is not installed.

    The following code has three ma!or parts. First it chec's to see if the installation is a newinstall or whether a maintenance operation has been invo'ed. The code chec's forwhether the Installed property has a value or not and this determines whether a newinstall or a maintenance operation is in progress. )uring a new installation the codechec's the )): % : property to see what features are being installed. (ased on thischec' the value of this property is modified appropriately.

    )uring a maintenance operation the code needs to chec' for any features that are beingadded and it also needs to chec' for any features that are being uninstalled. (ased onwhat is happening it can be necessary to modify the values of both the )): % : andthe >5M @5 properties. The following code is heavily commented so the best way foryou to understand what is happening is to read the comments and follow theimplementation of this custom action.

    **** T+is custo- !ction wi"" force t+e inst!""!tion of Fe!ture2** if Fe!ture3 is dese"ected4 T+e tec+ni5ue used is t+e** -!ni6u"!tion of t+e A((LOCAL 6u7"ic 6ro6ert8 t+!t is cre!ted** 78 t+e E9ecuteAction !ction4 T+e custo- !ction t+!t uses t+is** custo- !ction needs to 7e 6"!ced in t+e Inst!""E9ecuteSe5uence** t!7"e 6rior to t+e CostIniti!"i:e !ction4**'INT __stdc!"" SetFe!tureFour;MSIHAN(LE +Inst!""T;?,?

  • 8/11/2019 Working With Features

    15/32

    Working with Features 1*

    nc+!rCount = @

    if;ERROR_MORE_(ATA B= Msi&et$ro6ert8;+Inst!"",s:AddLoc!"$ro6, TE>T;??

  • 8/11/2019 Working With Features

    16/32

    Working with Features 1-

    ** t+ere wi"" not 7e ! co--! de"i-iter4 We t+en need** to set 6Fe!ture2End to 6oint to t+e end of** s:AddLoc!"V!"ue4

    if;B6Fe!ture2End< # nLen = _tcs"en;s:AddLoc!"V!"ue

  • 8/11/2019 Working With Features

    17/32

    Working with Features 1/

    continue@ ) e"se # s:AddLoc!"V!"ue i = .6Te-6@ i @ 6Te-6 @ ) )

    ** Add t+e N'LL c+!r!cter to t+e end of t+e ** s:AddLoc!"VA"ue strin14 s:AddLoc!"V!"ue i = G\ G@

    ** Set t+e /!"ue of t+e A((LOCAL 6ro6ert8 ** to 7e t+e "ist of fe!tures to 7e inst!""ed4 if;ERROR_S'CCESS B= MsiSet$ro6ert8;+Inst!"",

    s:AddLoc!"$ro6, s:AddLoc!"V!"ueT;??

  • 8/11/2019 Working With Features

    18/32

    Working with Features 10

    Mess!1eDo9;&etFore1roundWindow;T;??

  • 8/11/2019 Working With Features

    19/32

    Working with Features 1

    ** If t+e A((LOCAL 6ro6ert8 /!"ue is N'LL t+en ** we do not need ! de"i-iter if;7Added< # _tcsc!t;s:AddLoc!"V!"ue, s:(e"i-iter

  • 8/11/2019 Working With Features

    20/32

    Working with Features #2

    return ERROR_S'CCESS@)

    s you can see from the above code this approach to controlling feature selection can getrather messy. The ne$t e$ample does the same thing as this e$ample but it does it in aneasier fashion. The one benefit that this present e$ample has over the ne$t e$ample is that

    it can handle feature selection even during a silent installation.

    6sing the 3si"etFeatureState78 and 3siSetFeatureState78 functions

    In this e$ample we use two of the "indows Installer I functions that allow us to getand set feature states. The scenario is the same as in the previous e$ample where we donot want both Feature/ and Feature? to be on the system at the same. (ecause of thesimilarity of between this e$ample and the previous e$ample we will use the Features&

    pro!ect that you created for the last e$ample. This pro!ect ahs to be modified1 however1according to the following steps4

    &. pen the Features& pro!ect in InstallShield rofessional "indows Installer5dition.

    0. >emove the SetFeatureFour custom action from the Install5$ecuteSequence table.

    /. %reate an immediate "indows Installer ):: custom action that has the%trlFeatureFour e$ported function as the target. +ame this custom action thesame as the e$ported function name.

    ?. dd this custom action as a )o ction control event to the +e$t button on theSetupType dialog and to the +e$t button on the %ustomSetup dialog. "e want toadd this custom action to both buttons in case the end user does not choose to go

    into the %ustomSetup dialog but does define the features to be installed on thecommand line using either the )): % : or the I+ST :::5@5: properties.

    The following code is much simpler than what we had in the last e$ample. In thise$ample all we have to do is concern ourselves with the action state of Feature/ andFeature?. The list of possible action states for features is listed in Table & above. Thecomments in the following code clearly describe the process that is being implemented.In this custom action we are able to handle a new install as well as a maintenanceoperation without having to specifically chec' for the value of the Installed property.

    The first thing that is done is chec' for the action states of Feature/ and Feature?. Then in

    a switch statement we chec' for various values for the action state of Feature/. (ased onthis action state we can perform whatever operations are necessary to ma'e sure that bothFeature/ and Feature? are not installed at the same time. "e also ma'e sure that one ofthese features is always installed. Finally we ma'e a special chec' to ma'e sure that theI+ST :::5@5: property has not been set at the command line so that both Feature/and Feature? are being installed or that a maintenance operation is not being run whereno change is being made to the selection of Feature/.

    **

    The Official InstallShield Professional Windows Installer EditionDevelo er!s "uide

  • 8/11/2019 Working With Features

    21/32

    Working with Features #1

    ** T+is custo- !ction wi"" force t+e inst!""!tion of Fe!ture2** if Fe!ture3 is dese"ected4 T+e tec+ni5ue used is t+e** -!ni6u"!tion of t+e fe!ture st!te usin1 t+e Msi&etFe!tureSt!te** !nd MsiSetFe!tureSt!te A$Is4 T+e custo- !ction t+!t uses t+is** function is -!de t+e !r1u-ent of ! (oAction contro" e/ent on t+e** Ne9t 7utton of t+e Custo-Setu6 di!"o1 !nd on t+e Ne9t 7utton** of t+e Setu6T86e di!"o14**'INT __stdc!"" Ctr"Fe!tureFour;MSIHAN(LE +Inst!""T;?Fe!ture3?T;?Fe!ture2?

  • 8/11/2019 Working With Features

    22/32

    Working with Features ##

    MsiSetFe!tureSt!te;+Inst!"", s:Fe!tureFour,INSTALLSTATE_LOCAL

  • 8/11/2019 Working With Features

    23/32

    Working with Features #(

    In the ne$t e$ample we ta'e a loo' at one approach to controlling the features to beinstalled through the use of a serial number that the end user inputs.

    6sing a serial nu%&er after file costing to control feature install states

    In this e$ample we generate a scenario where the end user enters a serial number in the%ustomerInformation dialog and based on that serial number a certain subset of featuresis installed. Since we will be doing this after file costing we cannot allow the user accessto the SetupType dialog or to the %ustomSetup dialog. (ecause of this we have change

    both the installation and the maintenance wizard sequences to remove these two dialogs.

    In this e$ample we will create the functionality where the first three features will getinstalled for one serial number1 the ne$t three features for a second serial number1 and thelast three features for a third serial number. To create the Features0 pro!ect follow thesteps listed below4

    &. In InstallShield rofessional "indows Installer 5dition create a pro!ect namedFeatures0 using the (asicFeature%ontrol.ist template file.

    0. %reate an immediate "indows Installer ):: custom action that has theSerial+oFeatureSelection function as its target.

    /. lace this custom action on the +e$t button of the %ustomerInformation dialogusing the )o ction control event.

    ?. >edirect the +e$t button on the %ustomerInformation dialog so that it launchesthe >eadyToInstall dialog under all conditions.

    =. >edirect the +e$t button on the MaintenanceType dialog so that when the %hangeoption is selected the >eadyToInstall dialog is launched instead of the%ustomSetup dialog.

    edirect the (ac' button on the >eadyToInstall dialog so that it launches theMaintenanceType dialog and not the %ustomSetup dialog. For a first time installwe still want the %ustomerInformation dialog to be displayed so we do not touchthis particular control event.

    ;. In the roperty Manager set the value of the S5>I :+,MSB " property to &so that the mas'ed edit control will be visible in the %ustomerInformation dialog.

    The code for this custom action is shown below and the first thing it does is get the valueof the I)A5# property since this is the property that gets the serial number that the enduser inputs. The ne$t thing that this custom action does is to compare the value of this

    property to the valid serial numbers and if a match is made then the appropriate featuresare turned on or off according to the serial number. If a serial number is entered that is notvalid then the custom action displays a message bo$ and when the end user clic's the A

    button the installation is terminated. To get the first three features installed the valid serial

    The Official InstallShield Professional Windows Installer EditionDevelo er!s "uide

  • 8/11/2019 Working With Features

    24/32

  • 8/11/2019 Working With Features

    25/32

    Working with Features #*

    INSTALLSTATE_LOCALT;?Fe!ture2?T;?ADC ?

  • 8/11/2019 Working With Features

    26/32

    Working with Features #-

    INSTALLSTATE_ADSENTT;?Fe!tureQ?

  • 8/11/2019 Working With Features

    27/32

    Working with Features #/

    /. ttach this custom action to the +e$t button on the %ustomerInformation dialogusing the )o ction control event. %ondition this control event with the followingcondition4 +ot FT5>% STI+6. This condition will prevent the custom actionform running twice since if it did the complete feature tree would be destroyed.

    ?. pply a control condition to the Serial+umber control on the%ustomerInformation dialog so that it will be visible under the followingcondition4 S5>I :+,MSB " nd +ot FT5>% STI+61 and so that it will

    be hidden under the following condition4 +ot S5>I :+,MSB " rFT5>% STI+6. These conditions allow the mas'ed edit control to be visiblefor the first time through but if the user goes bac' after entering a serial numberthen they will not have the ability to enter a new serial number. pply these samecontrol conditions to the Serial:abel control.

    =. ,sing the roperty Manager set the value of the S5>I :+,MSB " property to&.

    emove the costing actions from the Install,ISequence table. These are all theactions that start with the %ostInitialize action and end with the %ostFinalizeaction. Instead of actually deleting them from the sequence table you can put acondition on them that will evaluate to false. This is done using a property thatdoes not e$ist for the condition.

    ;. ut a condition on each feature that will set the install level for the feature to 8 ifthe condition is true. For features Feature&1 Feature01 and Feature/ apply thecondition4 +ot C I)A5# E 2 (%-&0/3D1 for features Feature?1 Feature=1 andFeatuer< apply the condition4 +ot C I)A5# E 2 (%-?=% STI+6 property and sets itsvalue to &. Finally the custom action runs all the file costing standard actions by using the"indows Installer Msi)o ctionCD I function.

    **** T+is custo- !ction 6erfor-s fi"e costin1 in 6"!ce of** +!/in1 t+e fi"e costin1 !ctions 6"!ced in t+e Inst!""'ISe5uence** t!7"e4 It wi"" !"so set ! 6ro6ert8 to 7e used in ! condition** so t+!t t+is custo- !ction c!n 7e 6re/ented fro- runnin1 twice4

    The Official InstallShield Professional Windows Installer EditionDevelo er!s "uide

  • 8/11/2019 Working With Features

    28/32

    Working with Features #0

    **'INT __stdc!"" CostInst!"";MSIHAN(LE +Inst!""