How to use the pypsexec.paexec.ProcessPriority function in pypsexec

To help you get started, we’ve selected a few pypsexec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jborean93 / pypsexec / tests / test_paexec.py View on Github external
assert not actual['asynchronous'].get_value()
        assert not actual['dont_load_profile'].get_value()
        assert actual['interactive_session'].get_value() == 0
        assert actual['interactive'].get_value()
        assert not actual['run_elevated'].get_value()
        assert not actual['run_limited'].get_value()
        assert actual['password_len'].get_value() == 4
        assert actual['password'].get_value() == "pass".encode('utf-16-le')
        assert actual['username_len'].get_value() == 4
        assert actual['username'].get_value() == "user".encode('utf-16-le')
        assert not actual['use_system_account'].get_value()
        assert actual['working_dir_len'].get_value() == 0
        assert actual['working_dir'].get_value() == b""
        assert not actual['show_ui_on_win_logon'].get_value()
        assert actual['priority'].get_value() == \
            ProcessPriority.NORMAL_PRIORITY_CLASS
        assert actual['executable_len'].get_value() == 5
        assert actual['executable'].get_value() == "a.exe".encode('utf-16-le')
        assert actual['arguments_len'].get_value() == 4
        assert actual['arguments'].get_value() == "arg1".encode('utf-16-le')
        assert not actual['disable_file_redirection'].get_value()
        assert not actual['enable_debug'].get_value()
        assert actual['remote_log_path_len'].get_value() == 0
        assert actual['remote_log_path'].get_value() == b""
        assert not actual['no_delete'].get_value()
        assert actual['src_dir_len'].get_value() == 9
        assert actual['src_dir'].get_value() == \
            "C:\\source".encode('utf-16-le')
        assert actual['dest_dir_len'].get_value() == 9
        assert actual['dest_dir'].get_value() == \
            "C:\\target".encode('utf-16-le')
        assert actual['num_src_files'].get_value() == 2
github jborean93 / pypsexec / tests / test_client.py View on Github external
def test_proc_with_higher_priority(self, client):
        actual = client.run_executable("powershell.exe",
                                       arguments="Write-Host hi",
                                       priority=ProcessPriority.
                                       HIGH_PRIORITY_CLASS)
        assert actual[0] == b"hi\n"
        assert actual[1] == b""
        assert actual[2] == 0
        time.sleep(1)
github ansible / ansible / lib / ansible / modules / commands / psexec.py View on Github external
connection_password = module.params['connection_password']
    port = module.params['port']
    encrypt = module.params['encrypt']
    connection_timeout = module.params['connection_timeout']
    executable = module.params['executable']
    arguments = module.params['arguments']
    working_directory = module.params['working_directory']
    asynchronous = module.params['asynchronous']
    load_profile = module.params['load_profile']
    elevated = module.params['integrity_level'] == "elevated"
    limited = module.params['integrity_level'] == "limited"
    interactive = module.params['interactive']
    interactive_session = module.params['interactive_session']

    priority = {
        "above_normal": ProcessPriority.ABOVE_NORMAL_PRIORITY_CLASS,
        "below_normal": ProcessPriority.BELOW_NORMAL_PRIORITY_CLASS,
        "high": ProcessPriority.HIGH_PRIORITY_CLASS,
        "idle": ProcessPriority.IDLE_PRIORITY_CLASS,
        "normal": ProcessPriority.NORMAL_PRIORITY_CLASS,
        "realtime": ProcessPriority.REALTIME_PRIORITY_CLASS
    }[module.params['priority']]
    show_ui_on_logon_screen = module.params['show_ui_on_logon_screen']

    process_timeout = module.params['process_timeout']
    stdin = module.params['stdin']

    if connection_username is None or connection_password is None and \
            not HAS_KERBEROS:
        module.fail_json(msg=missing_required_lib("gssapi"),
                         execption=KERBEROS_IMP_ERR)
github jborean93 / pypsexec / pypsexec / paexec.py View on Github external
)),
            ('username', BytesField(
                size=lambda s: s['username_len'].get_value() * 2
            )),
            ('use_system_account', BoolField(size=1)),
            ('working_dir_len', IntField(
                size=4,
                default=lambda s: int(len(s['working_dir']) / 2)
            )),
            ('working_dir', BytesField(
                size=lambda s: s['working_dir_len'].get_value() * 2
            )),
            ('show_ui_on_win_logon', BoolField(size=1)),
            ('priority', EnumField(
                size=4,
                default=ProcessPriority.NORMAL_PRIORITY_CLASS,
                enum_type=ProcessPriority
            )),
            ('executable_len', IntField(
                size=4,
                default=lambda s: int(len(s['executable']) / 2)
            )),
            ('executable', BytesField(
                size=lambda s: s['executable_len'].get_value() * 2
            )),
            ('arguments_len', IntField(
                size=4,
                default=lambda s: int(len(s['arguments']) / 2)
            )),
            ('arguments', BytesField(
                size=lambda s: s['arguments_len'].get_value() * 2
            )),
github ansible / ansible / lib / ansible / modules / commands / psexec.py View on Github external
executable = module.params['executable']
    arguments = module.params['arguments']
    working_directory = module.params['working_directory']
    asynchronous = module.params['asynchronous']
    load_profile = module.params['load_profile']
    elevated = module.params['integrity_level'] == "elevated"
    limited = module.params['integrity_level'] == "limited"
    interactive = module.params['interactive']
    interactive_session = module.params['interactive_session']

    priority = {
        "above_normal": ProcessPriority.ABOVE_NORMAL_PRIORITY_CLASS,
        "below_normal": ProcessPriority.BELOW_NORMAL_PRIORITY_CLASS,
        "high": ProcessPriority.HIGH_PRIORITY_CLASS,
        "idle": ProcessPriority.IDLE_PRIORITY_CLASS,
        "normal": ProcessPriority.NORMAL_PRIORITY_CLASS,
        "realtime": ProcessPriority.REALTIME_PRIORITY_CLASS
    }[module.params['priority']]
    show_ui_on_logon_screen = module.params['show_ui_on_logon_screen']

    process_timeout = module.params['process_timeout']
    stdin = module.params['stdin']

    if connection_username is None or connection_password is None and \
            not HAS_KERBEROS:
        module.fail_json(msg=missing_required_lib("gssapi"),
                         execption=KERBEROS_IMP_ERR)

    win_client = client.Client(server=hostname, username=connection_username,
                               password=connection_password, port=port,
                               encrypt=encrypt)
github jborean93 / pypsexec / pypsexec / paexec.py View on Github external
('username', BytesField(
                size=lambda s: s['username_len'].get_value() * 2
            )),
            ('use_system_account', BoolField(size=1)),
            ('working_dir_len', IntField(
                size=4,
                default=lambda s: int(len(s['working_dir']) / 2)
            )),
            ('working_dir', BytesField(
                size=lambda s: s['working_dir_len'].get_value() * 2
            )),
            ('show_ui_on_win_logon', BoolField(size=1)),
            ('priority', EnumField(
                size=4,
                default=ProcessPriority.NORMAL_PRIORITY_CLASS,
                enum_type=ProcessPriority
            )),
            ('executable_len', IntField(
                size=4,
                default=lambda s: int(len(s['executable']) / 2)
            )),
            ('executable', BytesField(
                size=lambda s: s['executable_len'].get_value() * 2
            )),
            ('arguments_len', IntField(
                size=4,
                default=lambda s: int(len(s['arguments']) / 2)
            )),
            ('arguments', BytesField(
                size=lambda s: s['arguments_len'].get_value() * 2
            )),
            ('disable_file_redirection', BoolField(size=1)),
github jborean93 / pypsexec / pypsexec / client.py View on Github external
def run_executable(self, executable, arguments=None, processors=None,
                       asynchronous=False, load_profile=True,
                       interactive_session=0, interactive=False,
                       run_elevated=False, run_limited=False, username=None,
                       password=None, use_system_account=False,
                       working_dir=None, show_ui_on_win_logon=False,
                       priority=ProcessPriority.NORMAL_PRIORITY_CLASS,
                       remote_log_path=None, timeout_seconds=0,
                       stdout=OutputPipeBytes, stderr=OutputPipeBytes,
                       stdin=None, wow64=False):
        """
        Runs a command over the PAExec/PSExec interface based on the options
        provided. At a minimum the executable argument is required and the
        rest can stay as the defaults.

        The default configuration for a process (with no changes) is;
            User: The user that authenticated the SMB Session
            Elevation: Highest possible
            Working Dir: %SYSTEM_ROOT%\\System32
            Interactive: False
            Priority: Normal

        :param executable: (String) The executable to be run