jborean93 / pypsexec

Remote Windows execution like PsExec on Python
MIT License
113 stars 38 forks source link

remove_service throw exception #16

Open dingding72 opened 5 years ago

dingding72 commented 5 years ago

Hi, Jordan: thank you very much for the pypsexec package.

when I ran the sample code, it seemed like the connection, execution on the windows side were all working, however remove_service throw an exception:

Traceback (most recent call last): File "towin_test.py", line 36, in c.remove_service() File "/opt/miniconda3/lib/python3.7/site-packages/pypsexec/client.py", line 112, in remove_service self._service.delete() File "/opt/miniconda3/lib/python3.7/site-packages/pypsexec/scmr.py", line 326, in delete self._scmr.delete_service(self._handle) File "/opt/miniconda3/lib/python3.7/site-packages/pypsexec/scmr.py", line 478, in delete_service self._parse_error(return_code, "RDeleteService") File "/opt/miniconda3/lib/python3.7/site-packages/pypsexec/scmr.py", line 695, in _parse_error raise SCMRException(function_name, return_code, error_string) pypsexec.exceptions.SCMRException: Exception calling RDeleteService. Code: 1072, Msg: ERROR_SERVICE_MARKED_FOR_DELETE

any insights would be much appreciated!

jborean93 commented 5 years ago

Looks like we need to better handle removing a process that is already marked for deletion. I'll try to find some time to fix this up but currently juggling a few other things right now. For now you can just catch and ignore that exception with something like.

from pypsexec.exception import SCMRException

try:
    c.remove_service()
except SCMRException as exc:
    if exc.return_code == 1072:  # ERROR_SERVICE_MARKED_FOR_DELETE
        pass
    else:
        raise
whitesec121 commented 4 years ago

Gives the following error

Traceback (most recent call last): File "cwin.py", line 2, in from pypsexec.exception import SCMRException ImportError: No module named exception

mmoltenb commented 4 years ago

Gives the following error

Traceback (most recent call last): File "cwin.py", line 2, in from pypsexec.exception import SCMRException ImportError: No module named exception

The module is name exceptions so "from pypsexec.exceptions import SCMRException" should work