3

Possible Duplicate:
Hide Command Window in C# Application

in the console app, I want to run the cmd command, but a new window is being created, why ?

 Process process = new Process();
 ProcessStartInfo startInfo = new ProcessStartInfo();
 startInfo.WindowStyle = ProcessWindowStyle.Hidden;
 startInfo.CreateNoWindow = true;
 startInfo.UseShellExecute = false;
 startInfo.FileName = "cmd.exe";
 startInfo.WorkingDirectory = @"C:\m_f";
 startInfo.Arguments = "/c START _creator.bat";
 process.StartInfo = startInfo;
 process.Start();

edit

I had to change some code to:

 startInfo.FileName = @"C:\m_f\_creator.bat";
 startInfo.WorkingDirectory = @"C:\m_f\";
 startInfo.Arguments = "some_args";

now it works

4

1 回答 1

3

start spawns a new window, regardless of whether the parent shell has a window or not.

To run a batch file cmd /c foo.cmd suffices, or even foo.cmd.

于 2012-06-24T16:47:24.263 回答