0

I'm trying to enable dotnet 3.5 for a dependency for another application I'm installing. The problem is that my cmd shell that I'm using throws this error "'dism' is not recognized as an internal or external command, operable program or batch file." but if I copy and paste the string that I'm passing to the cmd shell:

Dism /online /LogPath:C:\Users\HollyPlyler\source\repos\installerOptimized\installerOptimized\bin\Debug\\Logs\DSIMEnableDotNet.log /LogLevel:4 /Enable-Feature /FeatureName:NetFx3

It works fine.

Here is my CMD class:

 class CommandLineTool
    {
        public async Task Com(String command, string logName)
        {
            Console.WriteLine("received " + command);
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.UseShellExecute = false;
            startInfo.CreateNoWindow = false;
            startInfo.RedirectStandardOutput = true;
            startInfo.UseShellExecute = false;
            startInfo.FileName = "CMD.exe";
            startInfo.Arguments = "/c " + command;
            process.StartInfo = startInfo;

            Task t = Task.Run(()=>process.Start());
            t.Wait();
            string output = process.StandardOutput.ReadToEnd();
            Console.BackgroundColor = ConsoleColor.Black;
            if (output.Contains("0/1"))
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                installerOptimized.install.success = false;
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Green;
                installerOptimized.install.success = true;
            }
            Console.WriteLine(output);
            string success = installerOptimized.install.success ? "successful" : "unsuccessful";
            System.IO.File.WriteAllLines("Logs/" + logName +"_" + success + ".txt", output.Split('\n'));
            process.WaitForExit();
    }
}
Holly Plyler
  • 339
  • 2
  • 10

1 Answers1

1

Okay, I've gotten it to work in this way. By creating a second class for DISM.exe. I might merge them and add a varialbe latter to optimize.

 class Dism
    {
        public async Task Com(String command, string logName)
        {
           Console.WriteLine("received " + command);
           System.Diagnostics.Process process = new System.Diagnostics.Process();
           System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
           startInfo.UseShellExecute = true;
           startInfo.CreateNoWindow = false;
           startInfo.RedirectStandardOutput = true;
           startInfo.UseShellExecute = false;
           startInfo.FileName = "Dism.exe";
           startInfo.Arguments = command;
        // startInfo.Arguments = command;
           process.StartInfo = startInfo;

           Task t = Task.Run(() => process.Start());
           t.Wait();
           string output = process.StandardOutput.ReadToEnd();
           Console.BackgroundColor = ConsoleColor.Black;
           if (output.Contains("0/1"))
           {
               Console.ForegroundColor = ConsoleColor.Yellow;
               installerOptimized.install.success = false;
           }
           else
           {
               Console.ForegroundColor = ConsoleColor.Green;
               installerOptimized.install.success = true;
           }
           Console.WriteLine(output);
           string success = installerOptimized.install.success ? "successful" : "unsuccessful";
           System.IO.File.WriteAllLines("Logs/" + logName + "_" + success + ".txt", output.Split('\n'));
           process.WaitForExit();
       }
   }

Call it like this:

 myDism.Com("/Online /LogPath:log.log /LogLevel:4 /Enable-Feature /FeatureName:NetFx3 /All", "dism");

Thank you.

Holly Plyler
  • 339
  • 2
  • 10