无法使用java中的openchannel访问远程计算机中的cmd提示符

无法使用java中的openchannel访问远程计算机中的cmd提示符,java,jsch,Java,Jsch,这是密码 I'm trying to access the cmd prompt in administrator mode and run a batch file in the remote machine,but right now I'm not able to access the cmd prompt through openchannel. Did anybody tried to access it from remote machine in java? 预期行为:set命

这是密码

I'm trying to access the cmd prompt in administrator mode and run a batch file in the remote machine,but right now I'm not able to access the cmd prompt through openchannel. Did anybody tried to access it from remote machine in java? 
预期行为:set命令应以管理员身份运行(尽管我已以管理员身份登录),返回c:drive(cd)并执行批处理文件ie;C:executeBatchFile.bat

实际行为:当我打印输出时,命令给出了用户路径(不是管理员)。ie;C:\Users\Admin\executeBatchFile.bat

你能提出同样的解决方案吗

java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
JSch jsch = new JSch();
session = jsch.getSession(user, ip, 22);
session.setPassword(password);
session.setTimeout(timeOut);
session.setConfig(config);
session.connect();
System.out.println("session connected");
//open command prompt to run the command = "C:\\executeBatchFile.bat" file
Channel channel = (ChannelExec) session.openChannel("exec");
((ChannelExec)channel).setCommand("cmd.exe /c \"echo %cd%\"\\executeBatchFile.bat");
channel.connect();
InputStream outputstream_from_the_channel = channel.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(outputstream_from_the_channel));
String jarOutput;
 while ((jarOutput = reader.readLine()) != null)
 {
  System.out.println("Inside while loop");
  System.out.println(jarOutput + "\n");
 }
reader.close();
session.disconnect();
有人能告诉我如何在管理员模式下打开cmd提示符吗(我仅使用管理员凭据登录,但在管理员模式下它仍然无法打开)。在这里,我需要在管理员模式下运行脚本。


有人能告诉我如何在管理员模式下打开cmd提示符吗(我只使用管理员凭据登录,但它仍然不能在管理员模式下打开)。在这里,我需要在administrator中运行脚本。

您是否尝试了FTP API?请将您的问题包括在程序中的相关代码中,并描述运行该脚本时发生的情况。包括您得到的任何错误消息或异常,包括堆栈跟踪。理想的,您应该发布一个小型的自包含程序,演示您遇到的问题。@Kenster-您能帮助我吗?问题是Windows在运行cmd.exe时没有继承管理权限。您是否尝试过FTP API?请回答您的问题,包括程序中的相关代码,并描述运行时发生的情况信息技术包括您得到的任何错误消息或异常,包括堆栈跟踪。理想情况下,您应该发布一个小型的自包含程序来演示您遇到的问题。@Kenster-您能帮我解决这个问题吗?问题是Windows在运行cmd.exe时,它不会继承管理权限。
This has been resolved using PsExec command instead of JSCH

String pscommand=E:\\Tool\\psexec -u user -p pwd \\\\ip -s -d cmd.exe /c C:\\executescript.bat

 process = Runtime.getRuntime().exec(pscommand);

      InputStream es = process.getErrorStream();

      BufferedReader errReader = new BufferedReader(new InputStreamReader(es));
      String line;

      // Read STDOUT into a buffer.
      while ((line = errReader.readLine()) != null)
      {
        system.out.println(line);
      }