简体   繁体   中英

Can't hide CMD window while running .bat file using C#

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?

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();
    }

The CreateNoWindow property might be what you are looking for.

fls1.StartInfo.CreateNoWindow = true;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM