Building An MSI File

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Building an MSI File: Visual Studio and Orca

(Page 1 of 6 ) In this chapter, youll build an installer package using a VS. !" Setup and #eploy$ent Pro%ect and look at it &ith a tool called 'rca, part of the (indo&s Installer S#). (The Definitive Guide to Windows Installer, by Phil (ilson, *press, IS+ , 1-./-.0.10.) Background 2irst, so$e history and an o3er3ie& of VSs capabilities in the installation area. 4icrosoft has often added capabilities for building installations in VS5 perhaps you3e used the Visual +asic Package and #eploy$ent (i6ard. If you3e used VS 6./, you $ight ha3e used the first 3ersion of Visual Studio Installer, &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 Installer packages &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 that 4icrosoft did a bad %ob, but it does $ean that if you &ant to use a substantial set of (indo&s Installers features, you should look beyond VS. !"s installer tool. 8ook in 9hapter 16 for a list 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<) an installer package called '=9*.4SI. *fter you3e installed it, youll find that the right>click conte?t $enu on (indo&s Installer files (notably packages, 4SI files and $erge $odules, 4S4 files) allo&s you to open and edit the$. :oull be using 'rca later to 3ie& and $odify installation packages. Ill describe e3erything I co3er here regarding (indo&s Installer concepts in $ore detail in later chapters. In this chapter, youll build an installer package so that you can look inside the actual 4SI file; thats &hen youll use 'rca.

Building an MSI File: Visual Studio and Orca - Building a Package


(Page 0 of 6 ) "he first package you build is a si$ple one5this is the @7ello (orldA progra$s eBui3alent in the installation conte?t. :oull install otepad ( '"!P*#.!C!) and a te?t file, together &ith a shortcut to run the installed otepad against the te?t file. ote that this pro%ect is supplied &ith the book, so you can build it yourself or use the one pro3ided.

: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 &i6ard has co$pleted, select the Pro%ect icon in the Solution !?plorer. "he !dit $enu has drop>do&n choices for Vie& >D !ditor >D 2ile Syste$. (hen youre in this 2ile Syste$ 3ie&, you can then select *pplication 2older. "hen you can right>click in the file pane and select *dd, then 2ile. *dd '"!P*#.!C! and So$e"e?t2ile.t?t in that pane. +ecause youll need a shortcut to '"!P*#.!C! for the Progra$s $enu, right>click '"!P*#.!C! in the file pane that you %ust added it to, and choose 9reate 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 Product a$e are enclosed in sBuare brackets. "hese are three standard (indo&s Installer properties. :oull see $ore of these later because properties are the 3ariables that dri3e the beha3ior of an installation. 2or no& the i$portant thing to kno& is that the 3alue of EProgra$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 a (indo&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 and select 9ut. "hen right>click the Gsers Progra$s 4enu ite$, select *dd >D 2older to add a folder and a subfolder (I called it Phil and "ry otepad), 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 properties to package files @In setup file.A 'ptions are here for bootstrappers (in other &ords, $aking sure that the (indo&s Installer engine is installed on the target syste$), but youll %ust be building the installer package, an 4SI file. See 2igure 0>0 for an e?a$ple of the property pages for the build.

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

Figure 2-3 Selecting the installation folder

"he installer has resol3ed the Progra$2iles2older property and the 2older bo? sho&s the actual path on the target syste$. "his is a key feature of (indo&s Installer properties5 not so $uch that they are resol3ed but that you can use the$ in sBuare brackets in places such as folder na$es and =egistry entries. I should point out that this folder isnt al&ays 9,IProgra$ 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 of the syste$< "his choice affects an i$portant (indo&s Installer property that you can control5the *88GS!=S property youll look at later.

Select !3eryone and continue. "he installation should co$plete nor$ally, and the Start 4enu should no& ha3e the shortcut to initiate otepad. :ou can uninstall the product in the usual &ays 3ia *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 the package and select !dit &ith 'rca. (hat you see is a screen like 2igure 0>L, &here 'rca sho&s each installer table in the left pane and the ro&s and colu$ns of each table on the right. (2igure 0>. sho&s a 3ie& &ith $ore tables sho&n.) In the case of 2igure 0>L, 'rca is sho&ing the 2ile table because its a useful place to start dissecting a package.

Figure 2-4. The File table +efore you go any further, the tables and their contents, including the details of each table and colu$n, are docu$ented in the (indo&s Installer section of the Platfor$ S#). I$ generally not going to repeat all that detail; Ill %ust point out ho& the tables &ork and fit together so that you 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 file in the 2ile a$e colu$n. If you hadnt guessed fro$ the for$at, the file na$e is sho&n in short file na$e and long file na$e for$at separated by a 3ertical bar. Perhaps $ore interestingly, the 2ile table sho&s the 3ersion for code files in the Version colu$n (&hich appears only if the file has a 3ersion resource). If you &ere thinking that (indo&s Installer uses this 3ersion 3alue to decide &hether to replace older 3ersions on the target syste$, youre right, and youll be using this 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$ponent is the key unit of an installation. "here is a co$ponent reference at al$ost e3ery place in the package &here so$ething is going to be installed onto the client syste$. VS has generated t&o co$ponents in the 2ile table, one for '"!P*#.!C! and one for the te?t file. If you3e installed so$ething and selected a @9usto$A install, youre probably used to the idea of a list of features that can be selected or deselected for installation. "he &ay this &orks in (indo&s Installer 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&ning feature. otice that VS generates only one feature, called #efault2eature. "his is one of the li$itations of VS, It has no capability to organi6e an installation into $ore than one feature. :ou also see $ore than %ust the t&o co$ponents in the 2ile table here. It turns out that VS &ants to be sure that the Progra$ 4enu folders get re$o3ed at uninstall ti$e. It adds a co$ponent and so$e entries in the =e$o3e2ile table to $ake sure that the Progra$ 4enu subfolders get deleted, and it creates a co$ponent because $ost acti3ities done during an installation reBuire an associated co$ponent. VS also creates a co$ponent to deal &ith so$e =egistry entries it $ight create ($ore on this later in this chapter).

Figure 2-5. The Feature Co ponents table

Building an MSI File: Visual Studio and Orca - 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 Shortcut table in the installation package. 2igure 0>6 sho&s the first fe& colu$ns of the 'rca 3ie& of the shortcut 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 a co$ponent. "here is also a #irectoryM colu$n, &hich effecti3ely na$es the Progra$ 4enu folder and the subfolders that contain the shortcut. "here is also an entry in the "arget colu$n that contains the na$e of the only feature in this installation. "he fact that this is the na$e of a feature in the 2eature table $eans that this is an @ad3ertisedA shortcut. *lthough ad3ertised features are associated &ith the @install on de$andA scenario, they ha3e another interesting characteristic, &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

you re$o3e the file '"!P*#.!C! fro$ its installed location on disk and then use the shortcut, 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 the actual target file5the installed '"!P*#.!C!. "hats because the linkage is indirect, through the co$ponent na$e in the Shortcut table. If you look at the 9o$ponent table in 2igure 0>1, the shortcut co$ponent is that top one, and that co$ponent has a )eyPath entry that is a key into the 2ile 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 indirectly referenced by na$ing a co$ponent that has a )eyPath entry referring to a 2ile table entry for a file. In other &ords, the Shortcut table na$es the co$ponent (not the file), and the 9o$ponent tables )eyPath entry points to the file. "heres another subtle point to notice here about the Shortcut, &hich is that a shortcut file is not literally being installed. *lthough it $ight ha3e looked as if you &ere installing an actual file in the I#!5a shortcut5the package contains no such file, %ust a table entry &ith the infor$ation reBuired to create one.

Figure 2-$. The Co ponent 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 because this shortcut is encoded &ith the special beha3ior that causes (indo&s to 3erify the presence of the installer co$ponent.

Figure 2-%. A Windows Installer shortcut

Building an MSI File: Visual Studio and Orca - More &out Pro'erties
(Page L of 6 ) (indo&s Installer properties are the 3ariables that you use to interact &ith the installation, such as the Progra$2iles2older property I $entioned. "heyre so$e&hat si$ilar to !n3iron$ent 3ariables in the sense that they are te?t>based 3ariables that define other te?t, standard ones are pro3ided 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$portant beha3iors, 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 its public, 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 is also 3isible throughout $ost of the installation seBuence. :ou cannot specify pri3ate

properties in a co$$and>line installation and you cant propagate the$ throughout the installation seBuences (co3ered in 9hapter -).
3. :ou can treat properties as if they &ere logical 3alues or data 3alues. Ill use the built>in

Version " property as an e?a$ple. "his property tells you &hether the syste$ youre installing 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 be conditioned on Version " as if it &ere a +oolean>3alued attribute. Its not unusual to see Version " as a condition in these situations. 7o&e3er, if you look at the actual 3alue of this property youll find it returns the 3ersion of the " fa$ily that is running. 'n (indo&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. If youre a 9 progra$$er, you $ight be fa$iliar &ith the idea that a 3alue is "rue if it is non> G88 in spite of its actual 3alue, so$e&hat like the beha3ior of so$e 9 language 3ariables.
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 because the conte?t usually defines ho& the data type &orks, but this 3agueness $ight &ell offend you if you are a progra$$er &ith a type>safe sensibility. *n installer package5a database5contains a Property table, &hich is &here you can define your o&n properties if you need to gi3e the$ default 3alues, and also set 3alues for standard installer 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$$atically setting 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 general is %ust a list of property na$es and property 3alues, so$e uppercase and public, so$e lo&ercase and pri3ate. +ecause this list contains both user>defined (added by VS &hen it built the package) and (indo&s InstallerPdefined properties, theres no &ay to distinguish bet&een &hat is a predefined installer property and &hat isnt, other than by looking in the S#) to see if its defined there. Product a$e and 4anufacturer are a$ong the standard installer properties that are defined here. 8ike $any other properties, these t&o end up on the syste$, &here they are a3ailable to be retrie3ed using *PI calls, or sho&n to the user in places such as the *ddK=e$o3e Progra$s 9ontrol Panel applet. ProductVersion is another installer property that you set, but unlike Product a$e and 4anufacturer, its 3alue is $ore than %ust infor$ational. (hen you look at upgrades and updating your product, youll see that incre$enting ProductVersion is a key step in the process.

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

Building an MSI File: Visual Studio and Orca - )*I+s: Product, *'grade, and Package -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 because its a con3enient $echanis$ to identify the product uniBuely. Its in &hat is called the =egistry for$at5te?t &ith curly braces around it. (indo&s uses the Product9ode property to identify this product uniBuely, and the (indo&s Installer Ser3ice uses it to deter$ine &hether your product is already present on a syste$.

"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, and each of these re3isions is intended as a replace$ent for the pre3ious 3ersion. "he Gpgrade9ode is the constant that links these re3isions together. :ou can think of an Gpgrade9ode as defining a product fa$ily. (indo&s can detect &hether a product containing a particular Gpgrade9ode has already been installed on a client syste$. It pro3ides a $echanis$ to uninstall the prior 3ersion as you install the ne& 3ersion, so that the replace$ent is a sea$less process instead of a 3isible uninstall follo&ed by an install of the ne&er product. !ach 3ersion replaces the prior 3ersion until 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 of 4icrosoft 'ffice that co$es out is a replace$ent for pre3ious 3ersions. 7o&e3er, if you look at the 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 of 4icrosoft 'ffice &ould all use the sa$e Gpgrade9ode, but VS. !" &ould ha3e a different Gpgrade9ode than VS 6./. "he &ay you build an installation to perfor$ a $a%or upgrade of a pre3ious 3ersion is co3ered in 9hapter 6. !ach indi3idual package5the 4SI file5is also identified by a QGI#5the Package9ode. "his is used to distinguish bet&een different builds of the sa$e product. If you run 'rca on an install package and choose Su$$ary Infor$ation fro$ the Vie& $enu, you see so$ething like 2igure 0>1/. "his sho&s the contents of the Su$$ary Infor$ation strea$ for this package, and it includes the Package9ode. (:ou can also see a si$ilar display &hen you choose Properties and Su$$ary fro$ the conte?t $enu &hen right>clicking a package, e?cept that the Package9ode is reported there as =e3ision u$ber.) "he co$bination of Product9ode and Package9ode is the &ay (indo&s kno&s &hat to do if you 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 $ode dialog. 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 is already installed on the syste$. +y definition, the fact that you are atte$pting to install the sa$e product (sa$e Product9ode) fro$ the sa$e package (Package9ode) $eans that you either &ant to repair or re$o3e it. o other choices $ake sense in this conte?t5the product is already installed, 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$$ary Infor$ation, then closing and sa3ing the file. (hen you atte$pt to install this package no&, you see different beha3ior. "his ti$e there is a $essage bo? fro$ (indo&s saying that @*nother 3ersion 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 beha3ior here. If you change only the Product9ode in the Property table using 'rca and then try to install the package, it &ould go into $aintenance $ode and ask for a =epair or =e$o3e. If you change the Product9ode and the Package9ode, (indo&s thinks its a totally ne& product and lets you go ahead &ith the installation.

Figure 2-1.. #SI file su

ar" infor ation

If you ha3e built a genuinely ne& package containing ne& files, you3e probably done so to ha3e it 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 and Orca - 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 contents of installation packages. 'ther *PIs interface &ith (indo&s to interact &ith the products installed on the syste$. "heres also a 9'4 interface that is e?posed $ainly for ad$inistrators. I say 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

in3entory of the package, and the second updates the package and $odifies it. "he co$plete scripts are in the sa$ple code associated &ith this chapter, and Ill go through the functionality a snippet 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, so first a V+Script creates the interface &ith code such as this, Dim installer Set 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 database Const 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. "he second para$eter says ho& you plan to use it. In this case, the 3alue 6ero $eans that you arent planning to update the package. :oure going to do an in3entory of the files in the package, so youll be setting up a SS8>like Buery into the 2ile table that you pre3iously looked at &ith 'rca. "his &orks using the concept of a @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 collection of records5 a dataset if you like. Dim "iew Set "iew = database.Open#iew ("S$%$C& '(ile)ame'!'#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 gra3e characters, 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 a3oid conflicts &ith reser3ed &ords. "he &ay you iterate through each of the records is to use the 2etch $ethod of the Vie& ob%ect, Dim record Set 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 2ile a$e, Version, 2ileSi6e, so String#ata(1) returns 2ile a$e, String#ata(0) returns Version, and String#ata(H) the 2ileSi6e, Dim a,ile a,ile = record.Strin-Data(.) "his gi3es you a string containing the 2ile a$e 3alue of the particular ro&. (hen all the =ecord ob%ects in the Vie& ha3e been returned &ith Vie&.2etch, the final returned =ecord ob%ect is

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 that loops through the 2ile table, you ha3e this code, Set "iew = database.Open#iew ("S$%$C& '(ile)ame'!'#ersion'! '(ileSi*e' (ROM '(ile'") "iew.$/ec0te Do Set record = "iew.(etc+ I, record Is )ot+in- &+en $/it Do a,ile = record.Strin-Data(.) a"ersion = record.strin-data (1) ,si*e = record.Strin-data (2) ,0llms- = ,0llms- 3 a,ile 3 " " 3 a"ersion 3 " " 3 ,si*e 3 "bcrl, %oop ms-bo/ ,0llms"he principles of updating the package are si$ilar. "o $ake this updating script a bit $ore interesting, it reads a te?t file consisting of a series of co$$ands that $odify the database. :ou use 2ileSyste$'b%ect to read the $odify.t?t file containing the co$$ands, Set ,so = CreateObject("Scriptin-.(ileSystemObject") Set a,ile = ,so.4et(ile("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 youre updating the package, so you open in transacted $ode. "his is i$portant &hen you close the database 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 this co$$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 you use the !?ecute $ethod of the Vie& ob%ect to cause the change to occur. Put this loop together to read the te?t file and e?ecute the SS8 updates, Dim t+ecommand! "iew Do t+ecommand = ts.readline Set "iew = database.Open#iew(t+ecommand) 6 C+ec7$rror "iew.$/ec0te 6 C+ec7$rror i, ts.5t$ndo,Stream t+en e/it do %oop

"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, I)S$R& I)&O 8roperty (8roperty.8roperty! 8roperty.#al0e) #5%9$S (:5R8;$%8%I)<:! :+ttp6==www.microso,t.com:) ote that this is in t&o general pieces. "he first na$es the table and the colu$ns into &hich data is being inserted in the for$ U"*+8!D. U9'8G4 D. "he second part lists the 3alues corresponding to those colu$ns. In this e?a$ple, *=P7!8P8I ) is a standard (indo&s Installer property that is displayed in the *ddK=e$o3e Progra$s applet as a @9lick here for support infor$ationA link. VSs installer doesnt let you specify one, so this e?a$ple sho&s the &ay you add one to point to 4icrosofts (eb site. If you refer to 2igure 0>., you see an e?isting 3alue for the property 2older2or$M*llGsers &ith a 3alue of 4!. :our second update changes the 3alue of that e?isting property in the property table fro$ its pre3ious 4! to no& say *88. 98D5&$ 8roperty S$& 8roperty.#al0e = :5%%: W;$R$ 8roperty.8roperty = :(older(orm>5ll9sers: (hen you opened the database, you opened it in transaction $ode. "his $eans that none of the changes you3e $ade are in the database package yet. "o sa3e the updates, you $ust co$$it the changes &ith the 9o$$it $ethod of the #atabase ob%ect, database.Commit o& that you3e been introduced to an e?a$ple of ho& to alter the content of an installation package outside the VS en3iron$ent, you $ay &onder about the effect on the installation of changing this particular 2older2or$M*llGsers property. VS. !" generates this property5its not a standard (indo&s Installer one. (hat happens here is that the 3alue of the 2older2or$M*llGsers property dri3es the state of the !3eryone or Just $e choice in the installation dialog sho&n in 2igure 0>H. *fter you change the property 3alue fro$ 4! to *88 &ith that Gpdate state$ent, &hen you install the ne& package youll note that the radio button no& defaults to !3eryone. 7o& did I kno& that *88 is a legal 3alue for the property 3alue< :ou $ight ha3e noticed that 'rca has a 2ind choice under the !dit $enu. If you do this 2ind and put 2older2or$M*llGsers in the @2ind &hatA te?t bo?, the search e3entually sho&s you a 9ontrol!3ent table that has an entry &ith a condition 2older2or$M*llGsersOV*88V (see 2igure 0>11). 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 the e?t button of the dialog. "his e3ent occurs &hen the user chooses the e?t button, and the e3ent sets the 3alue of the *88GS!=S property to 0 if 2older2or$M*llGsersOV*88V. Its this 3alue of the *88GS!=S property that deter$ines &hether the installation is for the current user or for the syste$ as a &hole ($eaning that the product is installed for all users of the syste$).

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 installation defaults 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$inistrati3e

pri3ileges, 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$e en3iron$ents. In particular, its unusual for applications to be installed on ser3ers for the installing user5its $uch $ore likely that the product is being installed for all users of the ser3er. 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 setting the *88GS!=S property accordingly. :ou can do that in the 9ontrol!3ent table in 2igure 0>11 by changing the *rgu$ent 3alue to 1 using 'rca. Su00ar1 :ou3e looked at building a basic installation package and seen so$e of the contents of the underlying database tables that are used during the installation. :ou3e had a brief look at (indo&s Installer properties and the *PIs that you can use to access database packages. 'ne of the key points to take a&ay fro$ this chapter is that a (indo&s Installer 9o$ponent is the basic unit of an installation, and youll co$e back to this idea $any $ore ti$es.

You might also like