开发者

How to run a bat file from a C# program?

so i need a simpl开发者_Go百科e function to run bat file. How to do such thing?


Process.Start("file.bat");


Take a look at Process.Start

In the simplest form, you can call it like this

Process.Start("thebatchfile.bat")


You may find you need to include the directory in the call;

using System.Diagnostics;

Process.Start(@"C:....\thebatfile.bat");

If for example the file takes arguments in (not for Bat file granted), they too can be added in the "Start()"method. Seperate Start("....thebatfile", "-s - t 3600"); with a comma. Intellisense is great for looking at the overload options of the method.


I don't know how this is any different, but in a project I inherited, we used Microsoft.VisualBasic.Interaction.Shell.

Shell("file.bat", AppWinStyle.NormalFocus, True, -1) The last two parameters specify if the calling program should wait for the command to finish, and how long it should wait for it to time out (-1 for forever)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜