好的,经过长时间的调查和反复试验,我能够实现在某些注册表项不存在时启动默认 Web 浏览器的目标。
我首先在注册表中检查了所需的条目
<!--Property that indicates whether .Net framework 4.0 is currently installed-->
<Property Id="NETFRAMEWORK40">
<RegistrySearch Id="NetFramework40" Root="HKLM" Key="Software\Microsoft\NET Framework Setup\NDP\v4\Full" Name="Install" Type="raw" />
</Property>
<!--Property that indicates whether 2007 Office Data Connectivity is currently installed-->
<Property Id="ODCINSTALLED">
<RegistrySearch Id="CheckODCVersion" Root="HKLM" Key="SOFTWARE\Classes\Installer\Products\000021091D0090400000000000F01FEC" Name="Version" Type="raw" />
</Property>
然后我将 WixUtilExtension 引用添加到项目并设置以下 3 个自定义操作:
<CustomAction Id="SetExec1" Property="WixShellExecTarget" Value="http://go.microsoft.com/fwlink/?LinkID=186913" />
<CustomAction Id="SetExec2" Property="WixShellExecTarget" Value="http://www.microsoft.com/downloads/en/details.aspx?familyid=7554f536-8c28-4598-9b72-ef94e038c891&displaylang=en" />
<CustomAction Id="LaunchBrowser" BinaryKey="WixCA" DllEntry="WixShellExec" Execute="immediate" Return="ignore" />
前 2 个自定义操作用于设置将在不同时间使用的 WixShellExecTarget 属性,最后一个自定义操作是使用 WixShellExec 实用程序启动默认浏览器。
然后我为我的安装程序 UI 设置了 2 个自定义对话框,只有 2 个带有短消息的简单消息框以及“是”和“否”按钮。以下只是其中一个消息框,因为它们的外观非常相似:
<Dialog Id="NetFRWDlg" Width="260" Height="95" Title="[ProductName] Installation" NoMinimize="yes">
<Control Id="Text" Type="Text" X="48" Y="15" Width="194" Height="40">
<Text>This setup requires the .NET Framework version 4.0. Please install the .NET Framework and run this setup again. The .NET Framework can be obtained from the web. Would you like to do this now?</Text>
</Control>
<Control Id="YesButton" Type="PushButton" X="72" Y="67" Width="56" Height="17" Default="yes" Cancel="yes" Text="[ButtonText_Yes]">
<Publish Event="DoAction" Value="SetExec1" Order="1">1</Publish>
<Publish Event="DoAction" Value="LaunchBrowser" Order="2">1</Publish>
<Publish Event="EndDialog" Value="Exit" Order="3">1</Publish>
</Control>
<Control Id="NoButton" Type="PushButton" X="132" Y="67" Width="56" Height="17" Default="no" Cancel="yes" Text="[ButtonText_No]">
<Publish Event="EndDialog" Value="Exit">1</Publish>
</Control>
<Control Id="Icon" Type="Icon" X="15" Y="15" Width="24" Height="24" ToolTip="Information icon" FixedSize="yes" IconSize="32" Text="[WarningIcon]" />
</Dialog>
然后我将这 2 个对话框添加到 InstallUISequence 表中:
<InstallUISequence>
<Show Dialog="NetFRWDlg" After="AppSearch">
(NOT Installed) AND (NOT NETFRAMEWORK40)
</Show>
<Show Dialog="ODCDlg" After="AppSearch">
(NOT Installed) AND (NOT ODCINSTALLED)
</Show>
<Show Dialog="Install_PAGE1" After="CostFinalize" />
</InstallUISequence>
为了简要说明这一切是如何结合在一起的,当安装程序启动时,它将使用 NETFRAMEWORK40 和 ODCINSTALLED 属性检查所需的注册表。在 InstallUISequence 期间,如果缺少这些注册表,将显示 NetFRWDlg 或 ODCDlg 对话框/消息框。然后,用户可以通过单击对话框/消息框的“是”按钮来选择启动默认浏览器以查看传入的 URL。在此过程中,设置 WixShellExecTarget 属性、启动默认浏览器和退出安装程序的一系列操作将执行。如果用户点击否,安装程序将直接退出。