WiX安装程序完成后,我想打开一个PDF文件。
我目前拥有的相关WiX XML是:
<Property Id="WixShellExecTarget" Value="[#Manual.pdf]" />
<CustomAction Id="ShowManual"
Return="ignore"
BinaryKey="WixCA"
DllEntry="WixShellExec"
Impersonate="yes" />
<InstallExecuteSequence>
<Custom Action="ShowManual" After="InstallFinalize">NOT Installed</Custom>
</InstallExecuteSequence>
在安装了PDF阅读器的计算机上,这一切都可以正常工作。但是,如果没有,Windows会弹出一条消息,提示“ Windows无法打开此类文件”。
有没有什么方法可以让WiX仅在ShellExecute
存在与PDF文件关联的应用程序时才尝试调用?还是有可能使呼叫无提示地静默失败而不显示任何错误?
我通过创建一个“即时”托管自定义操作来解决此问题,该操作在运行之后运行,InstallFinalize
并用于FindExecutable
在尝试打开应用程序之前检查该应用程序是否与PDF文件相关联:
[DllImport("shell32.dll", EntryPoint = "FindExecutable")]
private static extern long FindExecutable(string lpFile, string lpDirectory, StringBuilder lpResult);
[CustomAction]
public static ActionResult ShowPdf(Session session)
{
var installDir = session["INSTALLDIR"];
var pdfPath = Path.Combine(installDir, @"My Dir\My.pdf");
var pdfReaderPath = new StringBuilder(1024);
long lngResult = FindExecutable(pdfPath, String.Empty, pdfReaderPath);
if ((lngResult >= 32) && (!String.IsNullOrWhiteSpace(pdfReaderPath.ToString())))
{
Process.Start(pdfPath);
}
return ActionResult.Success;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句