我尝试使用 PSEXEC 工具在远程计算机上运行命令,它使用命令提示符成功运行,但在 ASP.NET 项目中失败,显示以下输出错误。
PsExec v2.11 - Execute processes remotely Copyright (C) 2001-2014 Mark Russinovich Sysinternals - www.sysinternals.com
The handle is invalid.
block 引用>Connecting to lnxdevx...
Starting PSEXESVC service on lnxdevx...
Connecting with PsExec service on lnxdevx...
Error deriving session key:.
这是我的示例 C# 代码。
Process p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardInput = true; p.StartInfo.FileName = @"C:\Windows\System32\PsExec.exe"; p.StartInfo.Arguments = "-u xxxxxx -p xxxxxxxxxx \\\\lnxdevx -i -d -w \"C:\\DIRECTORY\" cmd.exe /C dir"; p.Start(); string output = p.StandardOutput.ReadToEnd(); string errormessage = p.StandardError.ReadToEnd(); p.WaitForExit();
最佳答案
问题是您不必打开 psexec
,而是打开 cmd
,然后从那里运行 psexec。
您尝试执行的代码也是错误的,您需要使用
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe"; \\if it is in System32
startInfo.Arguments = "psexec -u xxxxxx -p xxxxxxxxxx \\machine *your stuff*";
process.StartInfo = startInfo;
process.Start();
我没有测试,但我很确定这会起作用:)
关于c# - PSEXEC 通过命令提示符运行成功,但在 ASP .Net/C# 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36014096/