1) 安裝時使用者權限的判斷
使用MSI程式進行安裝時,一般要進行使用者權限的判斷,可以使用内置的屬性Privileged進行判斷,也可以通過設定Package的相關屬性進行判斷。
Privileged屬性
<Condition Message="!(loc.InstallWarning)">Privileged</Condition>
當使用者不具備管理者權限時,安裝停止并給出提示消息。
使用Package屬性設定,一般來說有2中安裝方式,面向使用者和面向機器。
面向使用者指的是所有使用者下均進行安裝,而不需要操作權限,即所有的使用者均可安裝、解除安裝。而面向機器指的是要求一定的管理者權限來安裝或解除安裝程式。
Wix中的代碼為:
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine"/>
InstallScope為perMachine時面向機器,為perUser時為面向使用者。
2) patch更新方式實作
對于少量檔案的更新,Wix提供了patch的方式進行更新,不需要對所有的安裝源檔案進行覆寫,僅僅選擇更新後的檔案進行安裝。
具體流程為:
準備2分安裝源檔案,一份為原始的,一份為更新後的檔案
分别對2分安裝源檔案進行build操作,得到不同的msi安裝檔案
使用torch.exe 和 pyro.exe 工具對2份msi檔案進行分析,得到兩者之間的不同,整理出patch安裝檔案
執行個體:
Product.wxs:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="48C49ACE-90CF-4161-9C6E-9162115A54DD"
Name="WiX Patch Example Product"
Language="1033"
Version="1.0.0"
Manufacturer="Dynamo Corporation"
UpgradeCode="48C49ACE-90CF-4161-9C6E-9162115A54DD">
<Package Description="Installs a file that will be patched."
Comments="This Product does not install any executables"
InstallerVersion="200"
Compressed="yes" />
<Media Id="1" Cabinet="product.cab" EmbedCab="yes" />
<FeatureRef Id="SampleProductFeature"/>
</Product>
<Fragment>
<Feature Id="SampleProductFeature" Title="Sample Product Feature" Level="1">
<ComponentRef Id="SampleComponent" />
</Feature>
</Fragment>
<Fragment>
<DirectoryRef Id="SampleProductFolder">
<Component Id="SampleComponent" Guid="{C28843DA-EF08-41CC-BA75-D2B99D8A1983}" DiskId="1">
<File Id="SampleFile" Name="Sample.txt" Source="./$(var.Version)/Sample.txt" />
</Component>
</DirectoryRef>
</Fragment>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder" Name="PFiles">
<Directory Id="SampleProductFolder" Name="Patch Sample Directory">
</Directory>
</Directory>
</Directory>
</Fragment>
</Wix>
Patch.wxs:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Patch
AllowRemoval="yes"
Manufacturer="Dynamo Corp"
MoreInfoURL="http://www.dynamocorp.com/"
DisplayName="Sample Patch"
Description="Small Update Patch"
Classification="Update"
>
<Media Id="5000" Cabinet="RTM.cab">
<PatchBaseline Id="RTM"/>
</Media>
<PatchFamilyRef Id="SamplePatchFamily"/>
</Patch>
<Fragment>
<PatchFamily Id='SamplePatchFamily' Version='1.0.0.0' Supersede='yes'>
<ComponentRef Id="SampleComponent"/>
</PatchFamily>
</Fragment>
</Wix>
cmd指令依次為:
candle.exe -dVersion=1.0 product.wxs
light.exe product.wixobj -out 1.0/product.msi
candle.exe -dVersion=1.1 product.wxs
light.exe product.wixobj -out 1.1/product.msi
torch.exe -p -xi 1.0/product.wixpdb 1.1/product.wixpdb -out patch/diff.wixmst
candle.exe patch.wxs
light.exe patch.wixobj -out patch/patch.wixmsp
pyro.exe patch/patch.wixmsp -out patch/patch.msp -t RTM patch/diff.wixmst
最後得到的msp檔案即為patch更新檔案。
3) 安裝程式版本控制問題
在安裝程式更新時,假如product的id沒有改變,則表明該安裝程式不允許多個版本共存。
一般msi程式更新時,都需要用到UpGradeCode,這個屬性是安裝程式更新唯一标示。
4) 序列号驗證機制的加入
<Control Id="CDKeyNumber" Type="Edit" X="55" Y="80" Width="200" Height="15" Property="CDKEY"/>
<Control Id="CDKeyErrorInfo" Type="Text" X="55" Y="100" Width="200" Height="15" Hidden="yes" Text="!(loc.CDKeyError)">
<Condition Action="show"><![CDATA[CDKEY <> "123" AND CDKEYCHECK = "yes"]]></Condition>
</Control>
自定義一個安裝對話框,然後使用type為text的control控件,采用一個公用屬性 CDKEY 獲得使用者輸入的CDKey,然後定義一個CustomAction,對CDKey進行判斷即可。此處将CDKey限定為123。
更多使用者資訊要求的對話框:
<Fragment>
<UI>
<Dialog Id="UserRegistrationDlg" Width="370" Height="270" Title="[ProductName] [Setup]" NoMinimize="yes">
<Control Id="NameLabel" Type="Text" X="45" Y="73" Width="100" Height="15" TabSkip="no" Text="&UserName:" />"
<Control Id="NameEdit" Type="Edit" X="45" Y="85" Width="220" Height="18" Property="USERNAME" Text="{80}" />
<Control Id="OrganizationLabel" Type="Text" X="45" Y="110" Width="100" Height="15" TabSkip="no" Text="&Organization:" />"
<Control Id="OrganizationEdit" Type="Edit" X="45" Y="122" Width="220" Height="18" Property="COMPANYNAME" Text="{80}" />
<Control Id="CDKeyLabel" Type="Text" X="45" Y="147" Width="50" Height="10" TabSkip="no">
<Text>CD &Key:</Text>
</Control>
<Control Id="CDKeyEdit" Type="MaskedEdit" X="45" Y="159" Width="250" Height="16" Property="PIDKEY" Text="[PIDTemplate]" />
<Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="&Back">
<Publish Event="NewDialog" Value="[WixUI_UserRegistrationDlgBack]">1</Publish>
</Control>
<Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="&Next">
<Publish Event="ValidateProductID" Value="0">1</Publish>
<Publish Event="SpawnWaitDialog" Value="WaitForCostingDlg">CostingComplete = 1</Publish>
<Publish Event="NewDialog" Value="[WixUI_UserRegistrationDlgNext]">ProductID</Publish>
</Control>
<Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="Cancel">
<Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
</Control>
<Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="WixUI_Bmp_Banner" />
<Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes">
<Text>Please enter your customer information</Text>
</Control>
<Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
<Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes">
<Text>{/WixUI_Font_Title}Customer Information</Text>
</Control>
<Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />
</Dialog>
</UI>
</Fragment>
(選自WIx tutorial)
5) 如何給本機所有使用者安裝桌面快捷方式和開始菜單項
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine"/>
InstallScope 設定為 perMachine 即可。