C#中執(zhí)行批處理文件(*.bat)的方法代碼
更新時(shí)間:2013年03月03日 17:09:57 作者:
本文介紹一下在C#中執(zhí)行批處理文件(*.bat)的方法。
復(fù)制代碼 代碼如下:
static void Main(string[] args)
{
Process proc = null;
try
{
string targetDir = string.Format(@"D:\adapters\setup");//this is where mybatch.bat lies
proc = new Process();
proc.StartInfo.WorkingDirectory = targetDir;
proc.StartInfo.FileName = "mybatch.bat";
proc.StartInfo.Arguments = string.Format("10");//this is argument
proc.StartInfo.CreateNoWindow = false;
proc.Start();
proc.WaitForExit();
}
catch (Exception ex)
{
Console.WriteLine("Exception Occurred :{0},{1}", ex.Message,ex.StackTrace.ToString());
}
}
如果要運(yùn)行時(shí)隱藏dos窗口,需使用下面的代碼
復(fù)制代碼 代碼如下:
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
相關(guān)文章
C# 創(chuàng)建MDB數(shù)據(jù)庫(kù)、并存放表格數(shù)據(jù)的案例
這篇文章主要介紹了C# 創(chuàng)建MDB數(shù)據(jù)庫(kù)、并存放表格數(shù)據(jù)的案例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-01-01DevExpress之TreeList用法實(shí)例總結(jié)
這篇文章主要介紹了DevExpress之TreeList用法,對(duì)于C#初學(xué)者有一定的借鑒價(jià)值,需要的朋友可以參考下2014-08-08C#程序調(diào)用C++動(dòng)態(tài)庫(kù)(dll文件)遇到的坑及解決
這篇文章主要介紹了C#程序調(diào)用C++動(dòng)態(tài)庫(kù)(dll文件)遇到的坑及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-08-08