【发布时间】:2017-07-12 07:36:19
【问题描述】:
嗨,我正在尝试使用 PsExec 工具在我的远程计算机上执行 ipconfig,但我得到 Psexec 工具退出,错误代码为 0
这里是我使用的代码
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.Domain = txtDomainName.Text;
p.StartInfo.UserName = txtUser.Text;
p.StartInfo.Password = secure;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + @"PSTools\psexec.exe";
p.StartInfo.Arguments = String.Format(@"\\{0} /accepteula cmd.exe ipconfig /all > c:\output.log", ipAddress);
p.Start();
p.WaitForExit();
string output = string.Empty;
while (!p.StandardError.EndOfStream)
{
output += p.StandardError.ReadToEnd().ToString();
}
我们如何使用 psexec 工具读取输出我在做什么错误
【问题讨论】:
-
用WMI就可以得到同样的数据,不需要运行外部程序
-
实际上我要做的是运行我的应用程序,它将检查远程机器上的输出数据进程是否可访问以获取示例现在我正在获取 ipconfig,如果它工作正常,那么我将使用 psexec 工具来我的应用程序
-
您可以使用与 WMI、System.Automation 相同的命名空间中的类来执行此操作。您可以创建一个 Powershell 管道并指定它应该在远程计算机上执行
-
你能举个例子吗..