如何使用 java 在 windows ec2 上创建用户

how to create user on windows ec2 using java

我是 AWS 的新手,谁能帮助我如何使用 java 代码在虚拟机上创建用户。我已经创建了 windows ec2 实例并且能够使用 sshClient 进行连接,但无法创建用户。我不知道如何完成。

[我是stack overflow新手,格式不对请见谅]
回答我自己的问题......它可能会帮助某人.. 您可以使用执行命令在远程 windows... 示例:

public boolean executeCommands(String commands, SSHRequestParam param)
        throws Exception,IOException {
    boolean response = false;
    try {

        Connection conn = getConnection(param);
        Session sess = conn.openSession();

        sess.execCommand(commands);
        sess.waitForCondition(ChannelCondition.EXIT_SIGNAL, 0);

        InputStream stdout = new StreamGobbler(sess.getStdout());

        BufferedReader br = new BufferedReader(
                new InputStreamReader(stdout));
        while (true) {
            String line = br.readLine();
            if (line == null)
                break;
            response=true;
            System.out.println(line);
        }

        InputStream stderr = new StreamGobbler(sess.getStderr());
        BufferedReader br1 = new BufferedReader(new InputStreamReader(
                stderr));

        while (true) {
            String line = br1.readLine();
            if (line == null)
                break;
            response=false;
            System.out.println(line);
        }

        /* Show exit status, if available (otherwise "null") */

        System.out.println("ExitCode: " + sess.getExitStatus());

        /* Close this session */

        System.out.println("closing session");
        sess.close();
        closeConnection(conn);

    } catch (IOException e) {
        System.out.println("Exception..while executing command.: " + commands);
        e.printStackTrace();
    }
    System.out.println("Command executed : "+response);
    return response;
}

public void createUser(String userName, String password,SSHRequestParam param)
        throws Exception,IOException {
       String command = "net user " +userName+" "+password+" /add" ;
       if(executeCommands(command,param))
          System.out.println("User created successfully");
       else
           System.out.println("User didn't create....");
}

在上面的示例中,param 变量存储连接到服务器的参数,即主机名、用户名、密码....