【问题标题】:Execute command in remote pc using PsExec - c#使用 PsExec 在远程 pc 中执行命令 - c#
【发布时间】:2015-08-19 09:55:47
【问题描述】:

我正在尝试使用将在集线器/服务器 PC 上运行的控制台应用程序将远程 PC 设置为 Selenium 节点。

当程序在调试模式下运行时,我在'errorMessage'中得到以下文本

The handle is invalid.
Connecting to 200.200.20.200:5555...
Couldn't access 200.200.20.200:5555
Connecting to 200.200.20.200:5555...

服务器的 PsExec 位于:D:\PSTools\PsExec.exe
服务器IP: 100.100.10.100
远程IP:200.200.20.200
远程PC中的jar文件保存在:D:\Selenium\selenium-server-standalone.jar

要在远程电脑上运行的命令是

D:\Selenium>java -jar selenium-server-standalone.jar -role node -hub http://100.100.10.100/grid/register  

我错过了什么

private static void StartSeleniumNode()
        {
            Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.FileName = @"D:\PSTools\PsExec.exe";
            p.StartInfo.Arguments = @"\\200.200.20.200:5555 -u xyz -p abc123 -i -w D:\Selenium java -jar selenium-server-standalone.jar -role node -hub http://100.100.10.100:4444/grid/register";
            p.Start();

            string output = p.StandardOutput.ReadToEnd();
            string errormessage = p.StandardError.ReadToEnd();

            p.WaitForExit();
        }

【问题讨论】:

  • 当我手动运行命令在各自的计算机中设置集线器和节点时,它可以工作

标签: c# psexec sysinternals


【解决方案1】:

你应该可以自己解决这个问题

你给了我们:p.StartInfo.Arguments = @"\\200.200.20.200"; \\what should go here

你有你想要运行的命令

java -jar selenium-server-standalone.jar -role node -hub http://100.100.10.100/grid/register

您知道要在哪台 PC 上运行它。 你有 psexec 来获取你需要发送它的参数。

所以,它会像

D:\PSTools\PsExec.exe psexec \\remotepc -i -w D:\Selenium java -jar selenium-server-standalone.jar -role node -hub http://100.100.10.100/grid/register

尝试从你的命令行运行它,当你让命令行工作时。您已准备好对其进行编码(让我们假设它有效。)

您的代码将是

p.StartInfo.FileName = @"D:\PSTools\PsExec.exe";
p.StartInfo.Arguments = @"\\remotepc -i -w D:\Selenium java -jar selenium-server-standalone.jar -role node -hub http://100.100.10.100/grid/register"; 

【讨论】:

  • 为了完整起见,PsExec 的使用记录得很好on its download page at Microsoft
  • 是的.. 虽然 psexec 在我工作的地方被禁止,所以我当然用 c# 制作了自己的 :D
  • 刚试过,'errorMessage' 说无法访问 200.200.20.200:。是否必须传递远程 pc 的凭据
  • 您必须检查另一端,它尝试以什么身份登录,如果它以访客身份尝试..那么您可能需要添加凭据,通常当然它以当前用户身份运行..如果那没有权利,但是你说你有一个工作命令行..
  • 我已尝试使用凭据。 errorMessage 仍然说无法访问
猜你喜欢
  • 2011-09-18
  • 2017-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-28
  • 1970-01-01
相关资源
最近更新 更多