c# 调用cmd命令

private void Form1_Load(object sender, EventArgs e)
{
string A=" ";
Process p = new Process();
p.StartInfo.FileName = "cmd.exe"; //命令
p.StartInfo.UseShellExecute = false; //不启用shell启动进程
p.StartInfo.RedirectStandardInput = true; // 重定向输入
p.StartInfo.RedirectStandardOutput = true; // 重定向标准输出
p.StartInfo.RedirectStandardError = true; // 重定向错误输出
p.StartInfo.CreateNoWindow = true; // 不创建新窗口
p.Start();
p.StandardInput.WriteLine(A); //cmd执行的语句
p.StandardInput.WriteLine("mstsc /admin /v:172.16.12.252"); //退出
}

posted @ 2019-01-10 15:27  huangkeke  阅读(536)  评论(0)    收藏  举报