How to use the pypsexec.scmr.ServiceStatus 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_scmr.py View on Github external
def test_create_message(self):
        message = ServiceStatus()
        message['service_type'] = ServiceType.SERVICE_WIN32_OWN_PROCESS
        message['current_state'] = CurrentState.SERVICE_RUNNING
        message['controls_accepted'] = ControlsAccepted.SERVICE_ACCEPT_STOP
        message['win32_exit_code'] = 0
        message['service_specified_exit_code'] = 1
        message['check_point'] = 2
        message['wait_hint'] = 3
        expected = b"\x10\x00\x00\x00" \
                   b"\x04\x00\x00\x00" \
                   b"\x01\x00\x00\x00" \
                   b"\x00\x00\x00\x00" \
                   b"\x01\x00\x00\x00" \
                   b"\x02\x00\x00\x00" \
                   b"\x03\x00\x00\x00"
        actual = message.pack()
        assert len(message) == 28
github jborean93 / pypsexec / tests / test_scmr.py View on Github external
scmr_handle = scmr.open_sc_manager_w(
                session.connection.server_name,
                None,
                DesiredAccess.SC_MANAGER_CONNECT |
                DesiredAccess.SC_MANAGER_CREATE_SERVICE |
                DesiredAccess.SC_MANAGER_ENUMERATE_SERVICE)

            actual = scmr.enum_services_status_w(scmr_handle,
                                                 ServiceType.
                                                 SERVICE_INTERACTIVE_PROCESS,
                                                 EnumServiceState.
                                                 SERVICE_STATE_ALL)
            assert len(actual) > 0
            assert isinstance(actual[0]['display_name'], string_types)
            assert isinstance(actual[0]['service_name'], string_types)
            assert isinstance(actual[0]['service_status'], ServiceStatus)
        finally:
            if scmr_handle:
                scmr.close_service_handle_w(scmr_handle)
            scmr.close()
github jborean93 / pypsexec / tests / test_scmr.py View on Github external
def test_unpack_status(self):
        actual = ServiceStatus()
        data = b"\x10\x00\x00\x00" \
               b"\x04\x00\x00\x00" \
               b"\x01\x00\x00\x00" \
               b"\x00\x00\x00\x00" \
               b"\x01\x00\x00\x00" \
               b"\x02\x00\x00\x00" \
               b"\x03\x00\x00\x00"
        data = actual.unpack(data)
        assert len(actual) == 28
        assert data == b""
        assert actual['service_type'].get_value() == \
            ServiceType.SERVICE_WIN32_OWN_PROCESS
        assert actual['current_state'].get_value() == \
            CurrentState.SERVICE_RUNNING
        assert actual['controls_accepted'].get_value() == \
            ControlsAccepted.SERVICE_ACCEPT_STOP
github jborean93 / pypsexec / pypsexec / scmr.py View on Github external
while len(data) < buffer_size:
            read_data = self.handle.read(0, 4280)
            data += self._parse_pdu(read_data, opnum)

        return_code = struct.unpack("
github jborean93 / pypsexec / pypsexec / scmr.py View on Github external
def control_service(self, service_handle, control_code):
        # https://msdn.microsoft.com/en-us/library/cc245921.aspx
        opnum = 1

        data = service_handle
        data += struct.pack("
github jborean93 / pypsexec / pypsexec / scmr.py View on Github external
)),
            ('current_state', EnumField(
                size=4,
                enum_type=CurrentState
            )),
            ('controls_accepted', FlagField(
                size=4,
                flag_type=ControlsAccepted,
                flag_strict=False
            )),
            ('win32_exit_code', IntField(size=4)),
            ('service_specified_exit_code', IntField(size=4)),
            ('check_point', IntField(size=4)),
            ('wait_hint', IntField(size=4))
        ])
        super(ServiceStatus, self).__init__()
github jborean93 / pypsexec / pypsexec / scmr.py View on Github external
def query_service_status(self, service_handle):
        # https://msdn.microsoft.com/en-us/library/cc245952.aspx
        opnum = 6

        res = self._invoke("RQueryServiceStatus", opnum, service_handle)
        return_code = struct.unpack("