WIX enable Windows feature

后端 未结 3 799
小鲜肉
小鲜肉 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.

提交回复
热议问题