WIX enable Windows feature

巧了我就是萌 提交于 2019-12-01 07:54:18

David Gardiner's answer hinted at the correct solution in my case. Creating your own custom action is not necessary. Here is how to do it for a 64 bit installation of Windows:

First determine if MSMQ is installed:

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

Declare your custom actions. You need two. One to set a property to the path to dism, and another to execute it:

<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"/>

Finally specify the custom actions in the install sequence:

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

Because this can take a little bit of time I've added the following to update the installer status text:

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

You can also specify a rollback action if you want to remove MSMQ on installation failure.

You might consider the Quiet Execution Custom Action

Juan C. Becerra

The way I do it is by creating a DTF custom action that calls the dism.exe process. You get the same result and no command prompt is launched.

[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 parameters are set via the custom action data.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!