教程集 www.jiaochengji.com
教程集 >  脚本编程  >  Asp.net  >  正文 c# 调用批处理(bat)的实现代码

c# 调用批处理(bat)的实现代码

发布时间:2016-01-20   编辑:jiaochengji.com
在c#程序中调用批处理文件(bat),有需要的朋友可以参考下。

c#调用批处理文件。
 

复制代码 代码示例:
static void Main(string[] args)
{
Process proc = null;
try
{
string targetDir = string.Format(@"D:\myfiles\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());
}
}

如果要运行时隐藏dos窗口,需使用下面的代码
 

复制代码 代码示例:
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;

您可能感兴趣的文章:
c# 调用批处理(bat)的实现代码
dos批处理静默执行的方法(不弹出窗口)
什么是批处理
批处理批量安装字体的代码
批处理BAT生成随机数调用随机网站内容的方法
批量安装windows补丁的批处理(bat)脚本
批处理中Copy与Xcopy的区别有哪些
启动windows进程和延时关闭的批处理代码
批处理复制并覆盖文件的代码
创建目录结构的批处理脚本

[关闭]
~ ~