c#中执行多句dos命令

来源:互联网 发布:兽血天龙网络连接 编辑:程序博客网 时间:2024/05/21 17:33

例如
cd c:\program files\test
copy ":\exe\try.exe" "c:\program files\test" /y
c:\program files\test\try.exe
如何在C#中运行?不要写在文件中然后读入,应为有些密码我想写在里面
process.start()?
那样不是我要是有100句的话就出现100个command窗口?

private void abc()
{

Process p = new Process();

p.StartInfo.FileName = "cmd.exe";

p.StartInfo.UseShellExecute = false;

p.StartInfo.RedirectStandardInput = true;

p.StartInfo.RedirectStandardOutput = true;

p.StartInfo.RedirectStandardError = true;

p.StartInfo.CreateNoWindow = true;
p.Start ();


p.StandardInput.WriteLine("dir");
p.StandardInput.WriteLine("exit");
p.StandardInput.WriteLine("cd c:\");
p.StandardInput.WriteLine("exit");
p.StandardInput.WriteLine("dir");
p.StandardInput.WriteLine("exit");
p.StandardInput.WriteLine("cls");
p.StandardInput.WriteLine("exit");

p.Close ();
}


文章来至http://www.bysjlwdx.com/htm/27/398.htm
原创粉丝点击