PsExec&;通过C#处理,不显示输出
显然PsExec正在工作。这个代码有效。执行时,它从不返回错误。但它只是有时返回输出,当它返回输出时,它总是第一行。 ipconfig的第一行是“Windows IP配置”,错误框显示“ipconfig返回,错误代码为0”。 如果您用本地IP替换REMOTEPC,它将运行,您可以看到cmd短暂闪烁信息。所以它起作用了 我应该补充一点,我相信原因是在执行PsExec之后,它不会“退出”。因此,等待外国退出永远不会发生。当您在cmd窗口中单击X时,将显示框。有时与输出提到,或空白 但它从来没有输出整个东西,因为一些该死的原因!它永远不会读到最后PsExec&;通过C#处理,不显示输出,c#,.net,windows,cmd,psexec,C#,.net,Windows,Cmd,Psexec,显然PsExec正在工作。这个代码有效。执行时,它从不返回错误。但它只是有时返回输出,当它返回输出时,它总是第一行。 ipconfig的第一行是“Windows IP配置”,错误框显示“ipconfig返回,错误代码为0”。 如果您用本地IP替换REMOTEPC,它将运行,您可以看到cmd短暂闪烁信息。所以它起作用了 我应该补充一点,我相信原因是在执行PsExec之后,它不会“退出”。因此,等待外国退出永远不会发生。当您在cmd窗口中单击X时,将显示框。有时与输出提到,或空白 但它从来没有输出整
private void button1_Click(object sender, EventArgs e)
{
Process p = new Process();
p.StartInfo.FileName = @"C:\PsExec.exe";
p.StartInfo.Arguments = @"\\REMOTEPC -u USER -p PASS -s ipconfig /all";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
//p.StartInfo.RedirectStandardInput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
//Tried this method of getting the output too
// while (!p.HasExited)
//{
// output += p.StandardOutput.ReadToEnd();
// }
string error = p.StandardError.ReadToEnd();
p.WaitForExit();
MessageBox.Show(output);
MessageBox.Show(error);
}
您看到这个答案了吗?我建议您将输出管道化到一个文件中,稍后再阅读。