1

How can I shell out to a DOS application in VB.NET/C# and it not flash on screen. I rather it not appear because it flashes, it opens and then terminates after doing its processing.

MiscellaneousUser
  • 2,915
  • 4
  • 25
  • 44
  • 1
    Possible duplicate of [Hiding the process window, why isn't it working?](http://stackoverflow.com/questions/23246613/hiding-the-process-window-why-isnt-it-working) – cokeman19 Apr 08 '16 at 13:13

1 Answers1

1

I found this useful example. Quoted below:

static void LaunchCommandLineApp()
{
    // For the example.
    const string ex1 = "C:\\";
    const string ex2 = "C:\\Dir";

    // Use ProcessStartInfo class.
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.CreateNoWindow = false;
    startInfo.UseShellExecute = false;
    startInfo.FileName = "dcm2jpg.exe";
    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
    startInfo.Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2;

    try
    {
        // Start the process with the info we specified.
        // Call WaitForExit and then the using-statement will close.
        using (Process exeProcess = Process.Start(startInfo))
        {
            exeProcess.WaitForExit();
        }
    }
    catch
    {
        // Log error?
    }
}
Max Sorin
  • 1,042
  • 6
  • 14
  • Shouldn't `startInfo.CreateNoWindow = false;` be `true`? – Christoph Fink Apr 08 '16 at 12:55
  • Seems like `ProcessWindowStyle.Hidden;` does the same thing. Some applications may want a window to exist somewhere... I'd advise manipulating those settings until it works the exact way you want it to work. My answer was only meant to provide a means for accessing the process settings. – Max Sorin Apr 08 '16 at 12:59
  • Awesome, the WindowStyle fixed it. No more hard to stop the app when things going wrong :) Regards MiscellaneousUser a.k.a. Agent 005 – MiscellaneousUser Apr 08 '16 at 20:44