WIX enable Windows feature

后端 未结 3 797
小鲜肉
小鲜肉 2021-01-14 01:03

I have to check if some windows features are enabled beore installing my software.

I can check it or install it using dism command line tool.

I create a cust

相关标签:
3条回答
  • 2021-01-14 01:35

    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.

    0 讨论(0)
  • 2021-01-14 01:38

    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.

    0 讨论(0)
  • 2021-01-14 01:47

    You might consider the Quiet Execution Custom Action

    0 讨论(0)
提交回复
热议问题