Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
//p.StartInfo.Arguments = "tasklist /s 192.168.1.4 /u Administrator /p H9VW1KXP-TN27";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string strOutput = "";
try
{
p.Start();
p.StandardInput.WriteLine("tasklist /s 192.168.1.4 /u Administrator /p H9VW1KXP“);
p.StandardInput.WriteLine("exit");
strOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
}
catch (Exception ex)
{
//SDK.Log.Logger.GetLogger().Error(new AppException("读取失败”, ex));
}
p.StartInfo.FileName = "cmd.exe";
//p.StartInfo.Arguments = "tasklist /s 192.168.1.4 /u Administrator /p H9VW1KXP-TN27";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string strOutput = "";
try
{
p.Start();
p.StandardInput.WriteLine("tasklist /s 192.168.1.4 /u Administrator /p H9VW1KXP“);
p.StandardInput.WriteLine("exit");
strOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
}
catch (Exception ex)
{
//SDK.Log.Logger.GetLogger().Error(new AppException("读取失败”, ex));
}
strOutput 就是控制台命令返回的信息