【问题标题】:WIX enable Windows featureWIX 启用 Windows 功能
【发布时间】:2013-08-10 04:39:28
【问题描述】:

在安装我的软件之前,我必须检查是否启用了某些 Windows 功能。

我可以使用 dism 命令行工具检查或安装它。

我创建了一个自定义操作来执行此操作,但有没有办法以“WIX 原生方式”执行此操作?

<Property Id="dism" Value="dism.exe" />
<CustomAction Id="InstallMSMQContainer" Property="dism" ExeCommand=" /online /enable-feature /featurename:MSMQ-Container /featurename:MSMQ-Server /featurename:MSMQ-ADIntegration" Return="check" Impersonate="yes"  Execute="oncePerProcess"/>

<InstallUISequence>
  <Custom Action="InstallMSMQContainer" After="CostFinalize" Overridable="yes">NOT Installed</Custom>
</InstallUISequence>

问题是命令启动一个命令提示符,这对最终用户来说非常难看。 我怎样才能让它变得更好?我不知道我是否需要引导程序来执行此操作(例如安装 .NET Framework)。

是否有任何扩展来管理这些事情?

我现在使用的是 WIX 3.7。

【问题讨论】:

标签: wix wix3.7 wix-extension dism


【解决方案1】:

David Gardiner 的回答暗示了我的正确解决方案。不需要创建您自己的自定义操作。以下是 64 位 Windows 安装的方法:

首先判断是否安装了MSMQ:

<Property Id="MSMQINSTALLED">
  <RegistrySearch Id="MSMQVersion" Root="HKLM" Key="SOFTWARE\Microsoft\MSMQ\Parameters" Type="raw" Name="CurrentBuild" />
</Property>

声明您的自定义操作。你需要两个。一个设置属性到 dism 的路径,另一个执行它:

<CustomAction Id="InstallMsmq_Set" Property="InstallMsmq" Value="&quot;[System64Folder]dism.exe&quot; /online /enable-feature /featurename:msmq-server /all" Execute="immediate"/>
<CustomAction Id="InstallMsmq" BinaryKey="WixCA" DllEntry="CAQuietExec64" Execute="deferred" Return="check"/>

最后指定安装顺序中的自定义操作:

<InstallExecuteSequence>
  <Custom Action="InstallMsmq_Set" After="CostFinalize"/>
  <Custom Action="InstallMsmq" After="InstallInitialize">NOT REMOVE AND NOT MSMQINSTALLED</Custom> 
</InstallExecuteSequence>

因为这可能需要一点时间,所以我添加了以下内容来更新安装程序状态文本:

<UI> 
  <ProgressText Action="InstallMsmq">Installing MSMQ</ProgressText> 
</UI> 

如果要在安装失败时删除 MSMQ,还可以指定回滚操作。

【讨论】:

【解决方案2】:

【讨论】:

    【解决方案3】:

    我这样做的方法是创建一个调用 dism.exe 进程的 DTF 自定义操作。您会得到相同的结果,并且不会启动任何命令提示符。

    [CustomAction]
    public static ActionResult RunDism(Session session)
    {
        session.Log("Begin RunDism");
        string arguments = session["CustomActionData"];
    
        try
        {
            ProcessStartInfo info = new ProcessStartInfo();
            info.FileName = "dism.exe";
            session.Log("DEBUG: Trying to run {0}", info.FileName);
            info.Arguments = arguments;
            session.Log("DEBUG: Passing the following parameters: {0}", info.Arguments);
            info.UseShellExecute = false;
            info.RedirectStandardOutput = true;
            info.CreateNoWindow = true;
    
            Process deployProcess = new Process();
            deployProcess.StartInfo = info;
    
            deployProcess.Start();
            StreamReader outputReader = deployProcess.StandardOutput;
            deployProcess.WaitForExit();
            if (deployProcess.HasExited)
            {
                string output = outputReader.ReadToEnd();
                session.Log(output);
            }
            if (deployProcess.ExitCode != 0)
            {
                session.Log("ERROR: Exit code is {0}", deployProcess.ExitCode);
                return ActionResult.Failure;
            }
        }
        catch (Exception ex)
        {
            session.Log("ERROR: An error occurred when trying to start the process.");
            session.Log(ex.ToString());
            return ActionResult.Failure;
        }
        return ActionResult.Success;
    }
    

    DISM 参数通过自定义操作数据设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多