C# 无法使用psexec.exe远程启动进程
我无法使用psexec.exe远程启动进程。我的解决方案是这样的,我在服务器上有一个cmd脚本,它运行我的控制台应用程序。应用程序作业是在以下代码的帮助下,使用vstest.console.exe启动测试运行:C# 无法使用psexec.exe远程启动进程,c#,console-application,psexec,C#,Console Application,Psexec,我无法使用psexec.exe远程启动进程。我的解决方案是这样的,我在服务器上有一个cmd脚本,它运行我的控制台应用程序。应用程序作业是在以下代码的帮助下,使用vstest.console.exe启动测试运行: var config = LoadConfigFromFile<DeploymentStorage>(configFile); var currentDateTime = DateTime.Now; var resultFileName = String.For
var config = LoadConfigFromFile<DeploymentStorage>(configFile);
var currentDateTime = DateTime.Now;
var resultFileName = String.Format("testresults{0}{1}{2}{3}{4}{5}.trx",
currentDateTime.Year, currentDateTime.Month, currentDateTime.Day, currentDateTime.Hour, currentDateTime.Minute, currentDateTime.Second);
ProcessStartInfo processInfo =
new ProcessStartInfo(config.TestSettings.First(x => x.Key == "MSTestLocation").Value,
"\"" + config.TestSettings.First(x => x.Key == "TestContainer").Value + "\" /logger:trx;LogFileName=\"" +
config.TestSettings.First(x => x.Key == "TestResultLocation").Value + resultFileName + "\"");
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
var process = Process.Start(processInfo);
process.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
Console.WriteLine("output>>" + e.Data);
process.BeginOutputReadLine();
process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
Console.WriteLine("error>>" + e.Data);
process.BeginErrorReadLine();
process.WaitForExit();
var exitCode = process.ExitCode;
Console.WriteLine("ExitCode: {0}", exitCode);
process.Close();
其中TEST和base.config.xml的路径是传递给控制台应用程序的参数
EDIT2:看来我误解了我的问题。我从本地计算机上的命令行运行psexec.exe命令。它应该在服务器上运行名为TestApp的控制台应用程序。服务器上的这个控制台应用程序应该在上面代码的帮助下启动vstest.console.exe,而不是psexec.exe,它不能这样做。希望这能让事情变得更清楚一点
EDIT3:好的,我现在知道问题出在哪里了,如果我的测试容器是*.orderedtest文件,我不能远程运行测试。如果我尝试将dll设置为测试容器来运行测试,则一切正常。通常,在尝试此操作时,您需要做一些事情。我以前从C#执行过psexec,不幸的是,我不再有只在本地远程执行的代码,但其中一些代码将适用 1) 您可能需要使用管理员权限执行应用程序 有关如何执行此操作,请参见此处的答案: 2) 确保为PSEXEC启用了正确的参数。您需要确保您试图在远程计算机上执行的用户具有正确的访问权限 我建议尝试完全按照您的要求从提升的本地CMD提示符执行PSEXEC,以确保这是正确的 完整参数可在此处找到: 然后在代码中确保PSEXEC被指定为文件名,其他所有内容都被指定为参数。
确保路径用双引号括起来 这是我用过的一个例子
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = false;
startInfo.FileName = "C:\Data\Utils\psexec.exe";
startInfo.Arguments = "-u xxxx -p xxxx -accepteula" + " " + "\\\\remotemachine" + " " + "\"c:\\full\\path\\on\\remote\\machine\\myexecuteable.exe\"" + " " + " - other - agrs";
Process nProc = Process.Start(startInfo);
nProc.WaitForExit();
在您的代码中,您从哪里开始
psexec
?请发布一个。找出您试图执行的命令,尝试手动执行它,然后它工作吗?是的,如果我在服务器上本地运行TestApp,它工作。据我所知,psexec远程启动了我的TestApp,但是TestApp在用上面的代码启动vstest.console.exe时出现了问题。谢谢回复。问题是我没有尝试从控制台应用程序运行psexec。我尝试在psexec的帮助下运行服务器上的一个应用程序,其任务是启动另一个应用程序,在我的例子中是vstest.console.exe。
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = false;
startInfo.FileName = "C:\Data\Utils\psexec.exe";
startInfo.Arguments = "-u xxxx -p xxxx -accepteula" + " " + "\\\\remotemachine" + " " + "\"c:\\full\\path\\on\\remote\\machine\\myexecuteable.exe\"" + " " + " - other - agrs";
Process nProc = Process.Start(startInfo);
nProc.WaitForExit();