How to set default value of WiX Msi install path in the ui to Program Files?

回眸只為那壹抹淺笑 提交于 2020-07-23 18:04:41

问题


I have created a WiX installer MSI. When i run the msi, the installation path is asked for in the UI. Currently it loads the drive containing most of the free space. How can I set it to be at program files folder all the time? I tried the below line but it didn't work.

 <Property Id="WIXUI_INSTALLDIR" Value="C:\\Program Files\" />

Below is the error I get for the above element.

 The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2343. The arguments are: , , 

How can I make the UI load C:\Program Files as the default location all the time? Any help would be much appreciated.


回答1:


You want to make use of the already defined windows installer properties which are always defined by Windows Installer (caveat on some 64-bit only properties). In this case specifically the ProgramFilesFolder

Try using a directory definition like this:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLDIR" Name="MyProductFolder" />
            </Directory>
        </Directory>
    </Fragment>
</Wix>

And then, following the same principal as this quick tutorial page about using WixUI_InstallDir

You'll want to do

<Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />

Now when you show the UI page that lets you change the install location it should have the value C:\Program File\MyProductFolder

As a side-note, I would avoid making the install location just C:\Program Files because that may cause you to add a ton of extraneous files to this location where they should instead be contained in a product/program folder.

You should also never try to hardcode a path like "C:\Program Files\". In this specific case I can give you two quick examples why not to. There is no guarantee that the user is using the C:\ drive as their main drive or even uses a C:\ drive at all (one anecdote of this here). Another issue is (for 32-bit installs) on a 32-bit machine you'll want to install into the Program Files location but on a 64-bit machine you'll want to install into the "Program Files (x86)" location.



来源:https://stackoverflow.com/questions/43731235/how-to-set-default-value-of-wix-msi-install-path-in-the-ui-to-program-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!