title: Hide Command Window in C# Application
body: <p>Before you say its a duplicate question, please let me explain (as I've read all similar threads).</p>
  
  <p>My application has both of these settings:</p>
  
  <pre><code>  procStartInfo.CreateNoWindow = true;
    procStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  </code></pre>
  
  <p>and is also has WindowsApplication as the output type.  </p>
  
  <p>The black window STILL comes up when I call a command line command.  Is there anything else I can do to hide the window?  It doesn't happen for all commands, XCOPY is a situation where it the black window does flash up.  This only happens though when the destination I'm XCOPYing too already contains the file and it's prompting me if I want to replace it.  Even if I pass in /Y it will still flash briefly.</p>
  
  <p>I'm open to using vbscript if that will help, but any other ideas?</p>
  
  <p>The client will call my executable and then pass in a command line command ie:</p>
  
  <p><code>C:\MyProgram.exe start XCOPY c:\Test.txt c:\ProgramFiles\</code></p>
  
  <p>Here's the full code of the application:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {      
              string command = GetCommandLineArugments(args);
  
              // /c tells cmd that we want it to execute the command that follows and then exit.
              System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe", "/c " + command);
  
              procStartInfo.RedirectStandardOutput = true;
              procStartInfo.UseShellExecute = false;
  
              // Do not create the black window.
              procStartInfo.CreateNoWindow = true;
              procStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  
              System.Diagnostics.Process process = new System.Diagnostics.Process();
              process.StartInfo = procStartInfo;
              process.Start();
  
          }
  
      private static string GetCommandLineArugments(string[] args)
      {
          string retVal = string.Empty;
  
          foreach (string arg in args)
              retVal += " " + arg;
  
  
          return retVal;
      }
  }
  </code></pre>