Welcome to Dovetail Software Blogs : Sign in | Join | Help
Creating Windows Installers: Changing the Installation Path Using Registry Search

Joshua Flanagan had a question about my Web Applications and Virtual Directories post. He asks:

"Do you know of any way to query the default website root on the destination machine, so that you can use that as your target deployment folder?

For example, instead of deploying to c:\program files, I'd rather deploy the website to c:\inetpub\wwwroot, or whatever the root folder is for the default website."

Registry Search

This is really easy to do with the help of properties and our old friend (and sometimes enemy) the windows registry. The XML below defines a property that will be populated by a registry search. I did a quick search of the windows registry for c:\inetput\wwwroot and came up with the key below. Cavet: I have not researched that this key works for all versions of windows and IIS.

<Property Id="IISROOT" Value="#0"> <RegistrySearch Id="IISROOT" Type="raw" Root="HKLM" Key="Software\Microsoft\InetStp" Name="PathWWWRoot" /> </Property>

Now that we have a property containing the new default path we wish to install under we need to communicate this to Wix. Doing this is actually tricky.

Short Circuiting the TARGETDIR

At first I tried changing the value of the TARGETDIR property to but the files kept showing up in C:\ after installation. After doing a little googling and I found the answer in one of Dalun Software posts on Wix - How to Install Files to an Arbitrary Location Outside "Program Files". I am not sure how anyone could have figured this out from the documentation alone and I honestly don't understand why exactly this trick works. If you remove:

<Directory Id="dirDovetailPrograms" Name="Dovetail" LongName="Pants Enterprises">

And replace it with:

<Directory Id="IISROOT" Name=".">

Wix will use the value of the IISROOT property and short circuit the normal C:\Program Files\<company name>\<application name> pattern to be <IIS Root>\<application name>.

Here is an updated version of the pleats.wxs file does Josh's bidding:

<?xml version='1.0' encoding='Windows-1252'?> <Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'> <Product Name="Pants Enterprises Pleats" Id="{A263E591-B290-4db2-BF08-0C6FF24959A3}" Language="1033" Codepage="1252" Version="2.7.0" Manufacturer="Pants Enterprises Inc."> <Package Id="????????-????-????-????-????????????" Keywords="Pleats" Description="Pants Enterprises - Pleats" Comments="A web application for pants users." Languages="1033" Compressed="yes" SummaryCodepage="1252" /> <Media Id="1" Cabinet="Pleats.cab" EmbedCab="yes" DiskPrompt="CD-ROM #1" /> <Property Id="DiskPrompt" Value="Pants Enterprises - Pleats Installation [1]" /> <Property Id="IISROOT" Value="#0"> <RegistrySearch Id="IISROOT" Type="raw" Root="HKLM" Key="Software\Microsoft\InetStp" Name="PathWWWRoot" /> </Property> <Directory Id="TARGETDIR" Name="SourceDir"> <Directory Id="ProgramFilesFolder" Name="PFiles"> <Directory Id="IISROOT" Name="."> <Directory Id="INSTALLDIR" Name="Pleats"> <Component Id="pleatsIISIntegration" Guid="{63C11DB0-9ED2-4b63-9A4C-9A5C4C8CD599}"> <WebVirtualDir Id="pleatsVirtualDirectory" Directory="INSTALLDIR" Alias="Pleats" WebSite="DefaultWebSite"> <WebApplication Id="pleatsWebApplication" Name="Pleats"/> </WebVirtualDir> </Component> <Component Id="pleatsWebApplication" DiskId="1" Guid="{2431C807-01E6-4f16-9664-23CAE4E0BDF9}"> <File Id="file0" Name="admin.asp" Source="$(env.pleats.dir)\admin.asp" /> <File Id="file1" Name="admin2.asp" Source="$(env.pleats.dir)\admin2.asp" /> <!-- file2 <-> file47 elided for brevity --> <File Id="file48" Name="view.asp" Source="$(env.pleats.dir)\view.asp" /> <File Id="file49" Name="views.asp" Source="$(env.pleats.dir)\views.asp" /> </Component> <Directory Id="directory1" Name="docs"> <Component Id="pleatsDocumentation" DiskId="1" Guid="{EEC96333-0B40-49f8-A6BA-C7BDC53241E0}"> <File Id="file50" Name="pleats.chm" Source="$(env.pleats.dir)\docs\pleats.chm" /> </Component> </Directory> </Directory> </Directory> </Directory> </Directory> <WebSite Id="DefaultWebSite" Description="Default Web Site"> <WebAddress Id="AllUnassigned" Port="80" /> </WebSite> <Feature Id="Complete" Level="1"> <ComponentRef Id="pleatsWebApplication" /> <ComponentRef Id="pleatsDocumentation" /> <ComponentRef Id="pleatsIISIntegration"/> </Feature> <UIRef Id="WixUI_Minimal" /> </Product> </Wix>

Enjoy. If someone can explain the <Directory Id="[PropertyName]" Name="."/> Wix hack I would much appreciate it.

Posted: Thursday, December 13, 2007 12:06 PM by kmiller
Filed under: ,

Comments

Joshua Flanagan said:

Very cool (that you did my homework for me, not the fact that its an unintuitive hack). Thanks.

# December 14, 2007 12:46 PM

kmiller said:

@Joshua, I don't mind doing requests when I already know 50% of the answer and I get good post fodder out of it <grin/>

# December 14, 2007 12:54 PM

Kevin Miller said:

I recently built a small Monorail application and used my Wix-fu to build a deployment for it and thought

# March 7, 2008 5:44 PM