Home > Back-end >  Can't hide CMD window while running .bat file using C#
Can't hide CMD window while running .bat file using C#

Time:11-22

private void button1_Click_1(object sender, EventArgs e)
        {

            lbl_startingTest.Text = "Flashing DUT..";
            lbl_Result.Text = "Flash";
            
            Process fls1 = new Process();
            fls1.StartInfo.UseShellExecute = false;
            fls1.StartInfo.FileName = "C:\\test\\test\\bin\\Debug\\flash.bat";
            fls1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            fls1.Start();
            fls1.WaitForExit();
        }

I tried to use fls1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; to see if it hides CMD window. But when I run the application software it pops up CMD window when I click button on application. How can I hide the CMD window and still run .bat file in background?

CodePudding user response:

Try it without UseShellExecute = false; maybe change it to UseShellExecute to true.

 private void button1_Click_1(object sender, EventArgs e)
    {

        lbl_startingTest.Text = "Flashing DUT..";
        lbl_Result.Text = "Flash";
        fls1.StartInfo.UseShellExecute = true;
        Process fls1 = new Process();
        fls1.StartInfo.FileName = "C:\\test\\test\\bin\\Debug\\flash.bat";
        fls1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        fls1.Start();
        fls1.WaitForExit();
    }

CodePudding user response:

fls1.StartInfo.CreateNoWindow = true;

  • Related