+ All Categories
Home > Documents > Building an MSI File

Building an MSI File

Date post: 04-Jun-2018
Category:
Upload: bala-ratnakar-koneru
View: 222 times
Download: 0 times
Share this document with a friend

of 16

Transcript
  • 8/13/2019 Building an MSI File

    1/16

    Building an MSI File: Visual Studio andOrca

    (Page 1 of 6 )

    In this chapter, youll build an installer package using a VS.!" Setup and #eploy$ent Pro%ectand look at it &ith a tool called 'rca, part of the indo&s Installer S#. (The Definitive Guideto Windows Installer, by Phil ilson, *press, IS+ 1-/-00.)

    Background

    2irst, so$e history and an o3er3ie& of VSs capabilities in the installationarea.

    4icrosoft has often added capabilities for building installations in VS5perhaps you3e used the Visual +asic Package and #eploy$ent iard. If

    you3e used VS 6./, you $ight ha3e used the first 3ersion of Visual StudioInstaller, &hich &as a3ailable as a free do&nload for VS licensees. VS.!"is the first release of VS that integrates the ability to build indo&s Installerpackages &ith the I#!. 7o&e3er, VS.!"s installation tool co$es &ith

    so$e li$itations and restrictions that beco$e apparent as you use it. "his doesnt $ean that4icrosoft did a bad %ob, but it does $ean that if you &ant to use a substantial set of indo&sInstallers features, you should look beyond VS.!"s installer tool. 8ook in 9hapter 16 for alist of so$e of the 3endors that supply fully featured tools to create installer packages.

    'ne of the tools that 4icrosoft supplies to 3ie& and $odify installer packages is called 'rca.:ou can find it in the indo&s Installer section of the Platfor$ S#; the installation package is(&hat else

  • 8/13/2019 Building an MSI File

    2/16

    :ou start by running VS and choosing the e& Pro%ect fro$ the 2ile $enu, selecting Setup and#eploy$ent Pro%ect, and then Setup Pro%ect. 'nce the &iard has co$pleted, select the Pro%ecticon in the Solution !?plorer. "he !dit $enu has drop>do&n choices for Vie& >D !ditor >D 2ileSyste$. hen youre in this 2ile Syste$ 3ie&, you can then select *pplication 2older. "hen youcan right>click in the file pane and select *dd, then 2ile. *dd '"!P*#.!C! andSo$e"e?t2ile.t?t in that pane. +ecause youll need a shortcut to '"!P*#.!C! for theProgra$s $enu, right>click '"!P*#.!C! in the file pane that you %ust added it to, and choose9reate Shortcut. *t this point you should see so$ething like 2igure 0>1. otice that this 3ie&also sho&s the Properties &indo& for the *pplication 2older, &here Progra$2iles2older,4anufacturer, and Producta$e are enclosed in sBuare brackets. "hese are three standardindo&s Installer properties. :oull see $ore of these later because properties are the 3ariablesthat dri3e the beha3ior of an installation. 2or no& the i$portant thing to kno& is that the 3alue ofEProgra$2iles2olderF is resol3ed &hen the installation runs and is replaced &ith the Progra$2iles path on the syste$. "hose sBuare brackets $ean that the identifier they contain is aindo&s Installer property.

    Figure 2-1. VS's Application folder with shortcut

    :ou need the shortcut to otepad for the Gsers Progra$s 4enu, so right>click that shortcut andselect 9ut. "hen right>click the Gsers Progra$s 4enu ite$, select *dd >D 2older to add a folderand a subfolder (I called it Phil and "ryotepad), then use Paste to get the shortcut into the pane.:oull see so$ething like 2igure 0>1.

    +efore you do a build, right>click the Pro%ect in the Solution !?plorer and set the build propertiesto package files @In setup file.A 'ptions are here for bootstrappers (in other &ords, $aking surethat the indo&s Installer engine is installed on the target syste$), but youll %ust be buildingthe installer package, an 4SI file. See 2igure 0>0 for an e?a$ple of the property pages for the

    build.

  • 8/13/2019 Building an MSI File

    3/16

    Figure 2-2. VS's build options

    o& if you do a build it should create an installer package an 4SI file containing e3erythingneeded to install your otepad application. :ou can no& double>click the package and theinstallation starts. *fter the elco$e screen, you see a Select Installation folder thats got so$enotable features (see 2igure 0>H)

  • 8/13/2019 Building an MSI File

    4/16

    Figure 2-3Selecting the installation folder

    "he installer has resol3ed the Progra$2iles2older property and the 2older bo? sho&s theactual path on the target syste$. "his is a key feature of indo&s Installer properties5not so $uch that they are resol3ed but that you can use the$ in sBuare brackets in placessuch as folder na$es and =egistry entries. I should point out that this folder isnt al&ays9Progra$ 2iles, &hich is &hy indo&s Installer supplies a 3ariable property.

    "he dialog &ants to kno& &hether you &ant to install this application for Just $e or for

    !3eryone. In other &ords, should this be installed for the current user or for all users ofthe syste$< "his choice affects an i$portant indo&s Installer property that you cancontrol5the *88GS!=S property youll look at later.

    Select !3eryone and continue. "he installation should co$plete nor$ally, and the Start 4enushould no& ha3e the shortcut to initiate otepad. :ou can uninstall the product in the usual &ays3ia *ddK=e$o3e Progra$s, or by right>clicking the package and selecting Gninstall. 7o&e3er,youre going to look at the content of the package, so after you3e installed 'rca, right>click thepackage and select !dit &ith 'rca. hat you see is a screen like 2igure 0>L, &here 'rca sho&seach installer table in the left pane and the ro&s and colu$ns of each table on the right. (2igure0> sho&s a 3ie& &ith $ore tables sho&n.) In the case of 2igure 0>L, 'rca is sho&ing the 2iletable because its a useful place to start dissecting a package.

  • 8/13/2019 Building an MSI File

    5/16

    Figure 2-4. The File table

    +efore you go any further, the tables and their contents, including the details of each table andcolu$n, are docu$ented in the indo&s Installer section of the Platfor$ S#. I$ generallynot going to repeat all that detail; Ill %ust point out ho& the tables &ork and fit together so thatyou can $ake $ore sense of the docu$entation.

    otice that there is a ro& for each file youre installing, and that each ro& has the na$e of a filein the 2ilea$e colu$n. If you hadnt guessed fro$ the for$at, the file na$e is sho&n in shortfile na$e and long file na$e for$at separated by a 3ertical bar. Perhaps $ore interestingly, the2ile table sho&s the 3ersion for code files in the Version colu$n (&hich appears only if the filehas a 3ersion resource). If you &ere thinking that indo&s Installer uses this 3ersion 3alue todecide &hether to replace older 3ersions on the target syste$, youre right, and youll be usingthis 3alue &hen you get to 9hapter 6, &hich describes updating products.

    *n i$portant ite$ in the 2ile table is the 9o$ponentM colu$n. * indo&s Installer 9o$ponentis the key unit of an installation. "here is a co$ponent reference at al$ost e3ery place in thepackage &here so$ething is going to be installed onto the client syste$. VS has generated t&oco$ponents in the 2ile table, one for '"!P*#.!C! and one for the te?t file. If you3einstalled so$ething and selected a @9usto$A install, youre probably used to the idea of a list offeatures that can be selected or deselected for installation. "he &ay this &orks in indo&sInstaller is that a feature consists of one or $ore co$ponents. In fact, if you look at 2igure 0>-you see the 2eature9o$ponents table, &hich is &here co$ponents get $apped to their o&ningfeature. otice that VS generates only one feature, called #efault2eature. "his is one of theli$itations of VS It has no capability to organie an installation into $ore than one feature. :oualso see $ore than %ust the t&o co$ponents in the 2ile table here. It turns out that VS &ants to besure that the Progra$ 4enu folders get re$o3ed at uninstall ti$e. It adds a co$ponent and so$eentries in the =e$o3e2ile table to $ake sure that the Progra$ 4enu subfolders get deleted, andit creates a co$ponent because $ost acti3ities done during an installation reBuire an associatedco$ponent. VS also creates a co$ponent to deal &ith so$e =egistry entries it $ight create($ore on this later in this chapter).

  • 8/13/2019 Building an MSI File

    6/16

    Figure 2-5. The Feature Coponents table

    Building an MSI File: Visual Studio andOrca - First !ook at S"ortcuts

    (Page H of 6 )

    :ou installed a shortcut to otepad in this installation. *s you $ight e?pect, there is a Shortcuttable in the installation package. 2igure 0>6 sho&s the first fe& colu$ns of the 'rca 3ie& of theshortcut table and the entry for the shortcut to '"!P*#.!C!.

    Figure 2-#. The Shortcut table

    ote that the 9o$ponentM colu$n contains the indo&s Installer 9o$ponent that the shortcut

    belongs to5e?actly &hat you &ould e?pect kno&ing that all installed ite$s belong to aco$ponent. "here is also a #irectoryM colu$n, &hich effecti3ely na$es the Progra$ 4enufolder and the subfolders that contain the shortcut. "here is also an entry in the "arget colu$nthat contains the na$e of the only feature in this installation. "he fact that this is the na$e of afeature in the 2eature table $eans that this is an @ad3ertisedA shortcut. *lthough ad3ertisedfeatures are associated &ith the @install on de$andA scenario, they ha3e another interestingcharacteristic, &hich is that they 3erify the correctness of their associated installer co$ponents.In other &ords, using the shortcut triggers an auto$atic repair if the co$ponents are @broken.A If

  • 8/13/2019 Building an MSI File

    7/16

    you re$o3e the file '"!P*#.!C! fro$ its installed location on disk and then use theshortcut, you see a indo&s Installer dialog that restores the $issing file.

    *lthough the na$e of the shortcut is in the Shortcut table, there is no ob3ious reference to theactual target file5the installed '"!P*#.!C!. "hats because the linkage is indirect, throughthe co$ponent na$e in the Shortcut table. If you look at the 9o$ponent table in 2igure 0>, the

    shortcut co$ponent is that top one, and that co$ponent has a eyPath entry that is a key into the2ile table. =eferring back to 2igure 0>L, you can see that this 2ile table entry is '"!P*#.!C!."his is a specific case of a general principle in the installer5that a target file is indirectlyreferenced by na$ing a co$ponent that has a eyPath entry referring to a 2ile table entry for afile. In other &ords, the Shortcut table na$es the co$ponent (not the file), and the 9o$ponenttables eyPath entry points to the file. "heres another subtle point to notice here about theShortcut, &hich is that a shortcut file is not literally being installed. *lthough it $ight ha3elooked as if you &ere installing an actual file in the I#!5a shortcut5the package contains nosuch file, %ust a table entry &ith the infor$ation reBuired to create one.

    Figure 2-$. The Coponent table

    If you look at this actual shortcut &ith 'pen *ll Gsers in !?plorer, it looks like 2igure 0>N.9o$pared to noninstaller shortcuts, the "arget is grayed out and cant be altered. "his is becausethis shortcut is encoded &ith the special beha3ior that causes indo&s to 3erify the presence ofthe installer co$ponent.

  • 8/13/2019 Building an MSI File

    8/16

    Figure 2-%.A Windows Installer shortcut

    Building an MSI File: Visual Studio andOrca - More &out Pro'erties

    (Page L of 6 )

    indo&s Installer properties are the 3ariables that you use to interact &ith the installation, suchas the Progra$2iles2older property I $entioned. "heyre so$e&hat si$ilar to !n3iron$ent3ariables in the sense that they are te?t>based 3ariables that define other te?t, standard ones arepro3ided by indo&s, and you can define your o&n and so$eti$es set the indo&s ones.

    :oull be looking at properties in detail later, but be a&are that they ha3e so$e i$portantbeha3iors

    1. Properties are case>sensiti3e. If you create your o&n property na$e and refer to it later,be sure that you get the case correct.

    0. * property can be public or pri3ate. * public property $ust be in uppercase. If itspublic, you can specify it &ith a 3alue in a co$$and>line install of a package. *lso,because of the &ay that installations &ork internally, a public property that you create isalso 3isible throughout $ost of the installation seBuence. :ou cannot specify pri3ate

  • 8/13/2019 Building an MSI File

    9/16

    properties in a co$$and>line installation and you cant propagate the$ throughout theinstallation seBuences (co3ered in 9hapter -).

    3. :ou can treat properties as if they &ere logical 3alues or data 3alues. Ill use the built>inVersion" property as an e?a$ple. "his property tells you &hether the syste$ youreinstalling on is in the indo&s " fa$ily (", indo&s 0///, indo&s 0//H,indo&s CP). 2or e?a$ple, anything you do that depends on indo&s Ser3ices can beconditioned on Version" as if it &ere a +oolean>3alued attribute. Its not unusual to seeVersion" as a condition in these situations. 7o&e3er, if you look at the actual 3alue ofthis property youll find it returns the 3ersion of the " fa$ily that is running. 'nindo&s 0/// this property has the 3alue -//, and on CP the 3alue -/1. In other &ords,it can be used as a +oolean "rueK2alse 3alue e3en though it contains a 3ersion 3alue. Ifyoure a 9 progra$$er, you $ight be fa$iliar &ith the idea that a 3alue is "rue if it isnon>G88 in spite of its actual 3alue, so$e&hat like the beha3ior of so$e 9 language3ariables.

    4. "he data type of a property is 3ague. *s you3e seen, you can treat Version" as+oolean>3alued e3en if the actual 3alue of it is -//. If you &anted to check if you &ere

    running on indo&s 0/// or later, you $ight check for Version"DO-//. #oes this$ean its a string or a +oolean or a nu$ber< In practice it usually doesnt $atter becausethe conte?t usually defines ho& the data type &orks, but this 3agueness $ight &ell offendyou if you are a progra$$er &ith a type>safe sensibility.

    *n installer package5a database5contains a Property table, &hich is &here you can defineyour o&n properties if you need to gi3e the$ default 3alues, and also set 3alues for standardinstaller properties. :ou arent reBuired to declare your o&n properties in the Property table.#eclare the$ only if you need to gi3e the$ a default 3alue, because the act of progra$$aticallysetting a property na$e to a 3alue creates the property on the fly.

    8ooking at 2igure 0>, you see the Property table of your otepad package. "he table in generalis %ust a list of property na$es and property 3alues, so$e uppercase and public, so$e lo&ercaseand pri3ate. +ecause this list contains both user>defined (added by VS &hen it built the package)and indo&s Installerdefined properties, theres no &ay to distinguish bet&een &hat is apredefined installer property and &hat isnt, other than by looking in the S# to see if itsdefined there. Producta$e and 4anufacturer are a$ong the standard installer properties thatare defined here. 8ike $any other properties, these t&o end up on the syste$, &here they area3ailable to be retrie3ed using *PI calls, or sho&n to the user in places such as the *ddK=e$o3eProgra$s 9ontrol Panel applet. ProductVersion is another installer property that you set, butunlike Producta$e and 4anufacturer, its 3alue is $ore than %ust infor$ational. hen you lookat upgrades and updating your product, youll see that incre$enting ProductVersion is a key stepin the process.

  • 8/13/2019 Building an MSI File

    10/16

    Figure 2-(. The !ropert" table

    'ne of the key properties in an installation is the "*=Q!"#I= property. "his is the propertythat na$es the products pri$ary installation folder. It usually consists of a concatenation ofother standard properties, such as EProgra$2iles2olderFE4anufacturerFEProducta$eF, &hich is&hat VS creates as the default location for the application folder.

    Building an MSI File: Visual Studio andOrca - )*I+s: Product, *'grade, andPackage odes

    (Page - of 6 )

    :ou can see in 2igure 0> that the Product9ode property is in fact a QGI#, a uniBue identifier$ade fa$ous by its use in identifying 9'4 classes and interfaces. Its used here si$ply becauseits a con3enient $echanis$ to identify the product uniBuely. Its in &hat is called the =egistryfor$at5te?t &ith curly braces around it. indo&s uses the Product9ode property to identifythis product uniBuely, and the indo&s Installer Ser3ice uses it to deter$ine &hether yourproduct is already present on a syste$.

  • 8/13/2019 Building an MSI File

    11/16

    "he Gpgrade9ode is also a QGI# that you should not change &ithin the lifeti$e of a product."he idea behind Gpgrade9ode is that you &ill ha3e $a%or re3isions to a product o3er ti$e, andeach of these re3isions is intended as a replace$ent for the pre3ious 3ersion. "he Gpgrade9odeis the constant that links these re3isions together. :ou can think of an Gpgrade9ode as defining aproduct fa$ily. indo&s can detect &hether a product containing a particular Gpgrade9ode hasalready been installed on a client syste$. It pro3ides a $echanis$ to uninstall the prior 3ersionas you install the ne& 3ersion, so that the replace$ent is a sea$less process instead of a 3isibleuninstall follo&ed by an install of the ne&er product. !ach 3ersion replaces the prior 3ersionuntil a product arri3es that is co$pletely independent of the pre3ious 3ersions. In practice, this$ight be a $arketing decision as $uch as a technical one. 2or e?a$ple, each ne& 3ersion of4icrosoft 'ffice that co$es out is a replace$ent for pre3ious 3ersions. 7o&e3er, if you look atthe VS product line, VS.!" &as the start of a different product line5it did not replace VS 6./but could be installed alongside it. If you &ere designing these product lines, the 3ersions of4icrosoft 'ffice &ould all use the sa$e Gpgrade9ode, but VS.!" &ould ha3e a differentGpgrade9ode than VS 6./. "he &ay you build an installation to perfor$ a $a%or upgrade of apre3ious 3ersion is co3ered in 9hapter 6.

    !ach indi3idual package5the 4SI file5is also identified by a QGI#5the Package9ode. "hisis used to distinguish bet&een different builds of the sa$e product. If you run 'rca on an installpackage and choose Su$$ary Infor$ation fro$ the Vie& $enu, you see so$ething like 2igure0>1/. "his sho&s the contents of the Su$$ary Infor$ation strea$ for this package, and itincludes the Package9ode. (:ou can also see a si$ilar display &hen you choose Properties andSu$$ary fro$ the conte?t $enu &hen right>clicking a package, e?cept that the Package9ode isreported there as =e3ision u$ber.)

    "he co$bination of Product9ode and Package9ode is the &ay indo&s kno&s &hat to do ifyou try to reinstall the product. If you install your otepad package that you built in this chapter,then try to install the e?act sa$e package again, you see that it sho&s a $aintenance $odedialog. In this otepad installation, this $eans that the setup sho&s a dialog &ith choices for=epair or =e$o3e. indo&s kno&s that this product fro$ this package is already installed on

    the syste$, and the package itself is designed to go into this $aintenance $ode if the product isalready installed on the syste$. +y definition, the fact that you are atte$pting to install the sa$eproduct (sa$e Product9ode) fro$ the sa$e package (Package9ode) $eans that you either &antto repair or re$o3e it. o other choices $ake sense in this conte?t5the product is alreadyinstalled, after allR

    :ou can change the Package9ode by altering the =e3ision u$ber fro$ !?plorer (right>clicking, choosing Properties and the Su$$ary tab) or in the 'rca 3ie& of the Su$$aryInfor$ation, then closing and sa3ing the file. hen you atte$pt to install this package no&, yousee different beha3ior. "his ti$e there is a $essage bo? fro$ indo&s saying that @*nother3ersion of this product is already installedA and suggesting that you reconfigure fro$*ddK=e$o3e Progra$s. In other &ords, you ha3e to configure or re$o3e the e?isting installed

    product before you can install the ne& one. "he Package9ode deter$ines the initial beha3iorhere. If you change only the Product9ode in the Property table using 'rca and then try to installthe package, it &ould go into $aintenance $ode and ask for a =epair or =e$o3e. If you changethe Product9ode and the Package9ode, indo&s thinks its a totally ne& product and lets yougo ahead &ith the installation.

  • 8/13/2019 Building an MSI File

    12/16

    Figure 2-1.#SI file suar" inforation

    If you ha3e built a genuinely ne& package containing ne& files, you3e probably done so to ha3eit update or replace the e?isting product on the syste$. "his is the sub%ect of 9hapter 6. 2or no&,the point of this e?ercise is to de$onstrate the relationship bet&een Package9ode and

    Product9ode.

    Building an MSI File: Visual Studio andOrca - Into t"e Package /it" Progra00ing

    (Page 6 of 6 )

    indo&s has a collection of inH0 *PIs, all starting &ith 4si, that you can use on the contentsof installation packages. 'ther *PIs interface &ith indo&s to interact &ith the productsinstalled on the syste$. "heres also a 9'4 interface that is e?posed $ainly for ad$inistrators. Isay this because the 9'4 interface is scriptable, and V+Script &ith indo&s Script 7ost(S7) can take full ad3antage of it. :oull create t&o V+Scripts here "he first does an

  • 8/13/2019 Building an MSI File

    13/16

    in3entory of the package, and the second updates the package and $odifies it. "he co$pletescripts are in the sa$ple code associated &ith this chapter, and Ill go through the functionality asnippet at a ti$e. In the interests of readability, not e3erything is declared e?plicitly.

    "he scripting interface into indo&s Installer uses a ProgI# of @indo&sInstaller.InstallerA, sofirst a V+Script creates the interface &ith code such as this

    Dim installerSet installer = CreateObject("WindowsInstaller.Installer")

    ote that I$ skipping the error>checking code in these code frag$ents.

    ith an Installer ob%ect, you can no& open a database package

    Dim databaseConst msiOpenDatabaseModeReadOnly = Set database = installer.OpenDatabase("trynotepad.msi"! msiOpenDatabaseModeReadOnly )

    "he first para$eter to 'pen#atabase is si$ply the path to the package the actual 4SI file. "hesecond para$eter says ho& you plan to use it. In this case, the 3alue ero $eans that you arentplanning to update the package.

    :oure going to do an in3entory of the files in the package, so youll be setting up a S8>likeBuery into the 2ile table that you pre3iously looked at &ith 'rca. "his &orks using the concept ofa @3ie&A based on a Buery. * Vie& ob%ect is returned by calling the 'penVie& $ethod of the#atabase ob%ect, passing the Buery that returns the data. "he returned Vie& ob%ect is a collectionof records5 a dataset if you like.

    Dim iewSet iew = database.Open#iew("S$%$C& 'ileame'!'#ersion'! 'ileSi*e' ROM 'ile'")

    "his Buery should look fa$iliar if you3e &orked &ith databases. :oure getting ite$s fro$ the

    2ile table here; those ite$s correspond to the colu$n na$es in the 'rca 3ie& of the 2ile table.Incidentally, look carefully at &hat the colu$n na$es are surrounded by. "hose are gra3echaracters, so$eti$es kno&n as back Buotes or peck $arks T. "hey are not single Buotation$arks. It is usually safer to Buote the database content ite$s &ith gra3e characters to a3oidconflicts &ith reser3ed &ords.

    "he &ay you iterate through each of the records is to use the 2etch $ethod of the Vie& ob%ect

    Dim recordSet record = iew.etc+

    *t this point you ha3e a record a ro& fro$ the 2ile table. :ou can retrie3e each of the colu$ns&ith the String#ata property of the =ecord ob%ect. :ou retrie3e a single ite$ by inde?ing

    String#ata &ith an inde? that corresponds to its order in the original Buery, the S!8!9"state$ent. "he Buery order &as 2ilea$e, Version, 2ileSie, so String#ata(1) returns 2ilea$e,String#ata(0) returns Version, and String#ata(H) the 2ileSie

    Dim a,ilea,ile = record.Strin-Data()

    "his gi3es you a string containing the 2ilea$e 3alue of the particular ro&. hen all the =ecordob%ects in the Vie& ha3e been returned &ith Vie&.2etch, the final returned =ecord ob%ect is

  • 8/13/2019 Building an MSI File

    14/16

    e$pty, so the script can check to see if the =ecord ob%ect has the 3alue othing to find out&hether all the records ha3e been returned. Putting this all together into a code frag$ent thatloops through the 2ile table, you ha3e this code

    Set iew = database.Open#iew("S$%$C& 'ileame'!'#ersion'! 'ileSi*e' ROM 'ile'")

    iew.$/ec0teDo

    Set record = iew.etc+I, record Is ot+in- &+en $/it Doa,ile = record.Strin-Data()aersion = record.strin-data (1),si*e = record.Strin-data (2),0llms- = ,0llms- 3 a,ile 3 " " 3 aersion 3 " " 3 ,si*e 3

    bcrl,%oopms-bo/ ,0llms-

    "he principles of updating the package are si$ilar. "o $ake this updating script a bit $oreinteresting, it reads a te?t file consisting of a series of co$$ands that $odify the database. :ouuse 2ileSyste$'b%ect to read the $odify.t?t file containing the co$$ands

    Set ,so = CreateObject("Scriptin-.ileSystemObject")Set a,ile = ,so.4etile("modi,y.t/t")set ts = a,ile.Open5s&e/tStream (! )

    :ou create an Installer ob%ect and open the database package. 7o&e3er, this ti$e youreupdating the package, so you open in transacted $ode. "his is i$portant &hen you close thedatabase after your changes

    Const msiOpenDatabaseMode&ransact =

    Set database = installer.OpenDatabase("trynotepad.msi"! msiOpenDatabaseMode&ransact)

    Qi3en a co$$and that updates the database package, as in the pre3ious script you use the'penVie& $ethod of the #atabase ob%ect, passing the co$$and you e?pect to run. ith thisco$$and in a string called @theco$$andA that you get by reading the te?t file, you do the'penVie&

    Set iew = database.Open#iew(t+ecommand)

    +ecause youre updating, these co$$ands use 3erbs such as Gpdate, Insert, and #elete, so youuse the !?ecute $ethod of the Vie& ob%ect to cause the change to occur. Put this loop together toread the te?t file and e?ecute the S8 updates

    Dim t+ecommand! iewDo

    t+ecommand = ts.readlineSet iew = database.Open#iew(t+ecommand) 6 C+ec7$rroriew.$/ec0te 6 C+ec7$rrori, ts.5t$ndo,Stream t+en e/it do

    %oop

  • 8/13/2019 Building an MSI File

    15/16

    "he $odify.t?t file supplied &ith the book sa$ples has t&o updates. "he first inserts a ne&Property into the otepad installation that you built. "he te?t of this co$$and follo&s

    IS$R& I&O 8roperty (8roperty.8roperty! 8roperty.#al0e) #5%9$S(:5R8;$%8%I11). I &ont go into the deep details of dialog beha3ior here, but the 2older2or$ user dialog(the one &ith those !3eryoneKJust $e radio buttons) has a 9ontrol!3ent that is triggered off thee?t button of the dialog. "his e3ent occurs &hen the user chooses the e?t button, and thee3ent sets the 3alue of the *88GS!=S property to 0 if 2older2or$M*llGsersO*88. Its this3alue of the *88GS!=S property that deter$ines &hether the installation is for the current useror for the syste$ as a &hole ($eaning that the product is installed for all users of the syste$).

    http://www.microsoft.com/http://www.microsoft.com/
  • 8/13/2019 Building an MSI File

    16/16

    Figure 2-11.A$$%S&S in the Control&vent table

    "he *88GS!=S property is a indo&s Installer property that you can set to three states

    1. Gnspecified (G88 is ho& the S# docu$entation describes this). "he installationdefaults to a per>user installation.

    0. * 3alue of 1. "his $eans a per>syste$ installation, &ith the ca3eat that the installation&ill fail if the user does not ha3e ad$inistrati3e pri3ileges.

    3. * 3alue of 0. "his causes a per>syste$ installation if the user has ad$inistrati3epri3ileges, and a per>user installation if the user does not ha3e ad$inistrati3e pri3ileges.

    2or no&, Ill point out that the nondeter$inistic 3alue of 0 is likely to be un&elco$e in so$een3iron$ents. In particular, its unusual for applications to be installed on ser3ers for theinstalling user5its $uch $ore likely that the product is being installed for all users of theser3er. 7a3ing it accidentally installed for the current user could be a disaster, so in the cases&here you kno& ho& the product is intended to be installed and used, force the issue by settingthe *88GS!=S property accordingly. :ou can do that in the 9ontrol!3ent table in 2igure 0>11by changing the *rgu$ent 3alue to 1 using 'rca.

    Su00ar

    :ou3e looked at building a basic installation package and seen so$e of the contents of theunderlying database tables that are used during the installation. :ou3e had a brief look atindo&s Installer properties and the *PIs that you can use to access database packages. 'ne ofthe key points to take a&ay fro$ this chapter is that a indo&s Installer 9o$ponent is the basicunit of an installation, and youll co$e back to this idea $any $ore ti$es.


Recommended