Class WinRemoteCommandExecutor

java.lang.Object
org.metricshub.wmi.remotecommand.WinRemoteCommandExecutor

public class WinRemoteCommandExecutor extends Object
  • Method Details

    • getExecutionTime

      public float getExecutionTime()
      Get the execution time of the command in seconds.
      Returns:
    • getStdout

      public String getStdout()
      Get the stdout of the command.
      Returns:
    • getStderr

      public String getStderr()
      Get the stderr of the command.
      Returns:
    • getStatusCode

      public int getStatusCode()
      Get the return status code of the command
      Returns:
    • execute

      public static WinRemoteCommandExecutor execute(String command, String hostname, String username, char[] password, String workingDirectory, long timeout, List<String> localFileToCopyList, boolean mergeStdoutStderr) throws IOException, TimeoutException, WqlQuerySyntaxException, WindowsRemoteException
      Execute a command on a remote Windows system and return an object with the output of the command.

      You can specify local files to be copied to the remote system before executing the command. If the command contains references to these local files, it will be updated to reference the path on the remote system where the files have been copied.

      Example:

      WinRemoteCommandExecutor.execute("CSCRIPT c:\\MyScript.vbs", "remote-srv", null, null, null, 30000, Arrays.asList("c:\\MyScript.vbs"), false);

      This will copy c:\\MyScript.vbs to remote-srv, typically in C:\\Windows\\Temp\\SEN_ShareFor_MYHOST and the command that is executed will therefore become: CSCRIPT "C:\\Windows\\Temp\\SEN_ShareFor_MYHOST\\MyScript.vbs"

      Parameters:
      command - The command to execute. (Mandatory)
      hostname - Host to connect to. (Mandatory)
      username - The username name.
      password - The password.
      workingDirectory - Path of the directory for the spawned process on the remote system (can be null)
      timeout - Timeout in milliseconds
      localFileToCopyList - List of local files to copy to the remote before the execution
      mergeStdoutStderr - Whether to merge stderr with stdout or retrieve them separately
      Returns:
      an instance of WinRemoteCommandExecutor with the result of the command
      Throws:
      IOException - If an I/O error occurs.
      TimeoutException - To notify userName of timeout.
      WqlQuerySyntaxException - On WQL syntax errors
      WindowsRemoteException - For any problem encountered on remote