{"library":"pypsexec","title":"Run commands on a remote Windows host using SMB/RPC","description":"pypsexec is a Python library that enables running commands on a remote Windows host via SMB/RPC, similar to the popular PsExec tool. It achieves this by deploying and using a bundled PAExec executable on the remote target. The library is currently at version 0.3.0, with the last major release in October 2021, suggesting a maintenance release cadence.","language":"python","status":"maintenance","last_verified":"Thu Apr 16","install":{"commands":["pip install pypsexec"],"cli":null},"imports":["from pypsexec.client import Client"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom pypsexec.client import Client\n\nhostname = os.environ.get('PSEXEC_HOST', 'your_windows_host')\nusername = os.environ.get('PSEXEC_USERNAME', 'your_username')\npassword = os.environ.get('PSEXEC_PASSWORD', 'your_password')\n\nif not all([hostname, username, password]):\n    print(\"Please set PSEXEC_HOST, PSEXEC_USERNAME, PSEXEC_PASSWORD environment variables.\")\n    exit(1)\n\nc = Client(hostname, username=username, password=password, encrypt=True)\ntry:\n    c.connect()\n    c.create_service()\n    # Run 'whoami.exe /all' command\n    stdout, stderr, rc = c.run_executable('whoami.exe', arguments='/all')\n\n    print(f\"STDOUT:\\n{stdout.decode('utf-8') if stdout else ''}\")\n    print(f\"STDERR:\\n{stderr.decode('utf-8') if stderr else ''}\")\n    print(f\"Return Code: {rc}\")\nfinally:\n    c.remove_service()\n    c.disconnect()\n","lang":"python","description":"This example connects to a remote Windows host, creates a temporary service to execute a command ('whoami.exe /all'), captures its output, and then cleans up the service and connection. Credentials are pulled from environment variables.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}