Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WiX安装后打开PDF文件,不显示任何错误_Wix_Shellexecute_Wix3.8 - Fatal编程技术网

WiX安装后打开PDF文件,不显示任何错误

WiX安装后打开PDF文件,不显示任何错误,wix,shellexecute,wix3.8,Wix,Shellexecute,Wix3.8,我想在WiX安装程序完成后打开一个PDF文件 我目前拥有的相关WiX XML是: <Property Id="WixShellExecTarget" Value="[#Manual.pdf]" /> <CustomAction Id="ShowManual" Return="ignore" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" /> <Inst

我想在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无法打开这种类型的文件”


如果存在与PDF文件相关联的应用程序,有没有办法让WiX只尝试调用
ShellExecute
?或者可以让调用在不显示任何错误的情况下以静默方式失败吗?

我通过创建一个“立即”托管自定义操作来解决这个问题,该操作在
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;
}

您不能执行RegistrySearch以查看扩展是否已被处理,并将其作为您的应用程序的一个条件吗CustomAction@CheGueVerra我没有想到这一点,但我知道所需的注册表项可以根据Windows的版本进行更改。如果可能的话,我宁愿避免使用注册表。您可以通过搜索相应的注册表值来检测Windows的版本。否则,我看不出你如何检查你是否可以打开PDFI。不要认为不同版本的窗口上的位置会改变,但我没有检查。在HKCR\.pdf下寻找一些东西是一个开始,但你是对的,它可能不可靠。否则,在尝试打开pdf之前,您需要先运行在pdf上执行ShellExecute的代码。@PhilDW我已选中,并且Windows 8上未设置HKCR\.pdf值,因此不同版本之间存在差异不需要的代码。增加依赖性和脆弱性。有一种更简单、更优雅的方法来完成需求。@ChristopherPaint很公平,但我不认为构建和捆绑一个单独的可执行文件要简单得多。我还确认了注册表方法比您想象的要复杂,因为Windows 8中没有设置HKCR\.pdf值。我宁愿使用定义良好的API,它在所有Windows版本中都是一致的