Skip to main content

A cross-platform command launcher for administrator privileges.

Project description

py-admin-launch

A cross-platform Python command/helper to launch a specified program with administrator privileges.

Strategy

  • Linux desktop: pkexec for polkit GUI authentication, falling back to sudo when pkexec is not available.
  • Windows: ShellExecuteW(..., "runas", ...).
  • macOS: osascript + with administrator privileges, falling back to sudo when osascript is not available.

If the current process is already administrator/root, the command is launched directly as the current user.

CLI

Run from source:

python -m py_admin_launch -- your-command arg1 arg2

After installing the package:

py-admin-launch -- your-command arg1 arg2

Useful options:

py-admin-launch --wait --cwd /path/to/workdir -- your-command arg1 arg2

--wait makes py-admin-launch wait until the launched command exits and then return that command's exit code when the platform launcher supports it. Without --wait, py-admin-launch only starts the command and returns after the elevation request is handed off.

On Windows, elevated launches use ShellExecuteW(..., "runas", ...), which does not provide a child process handle to this helper. That means --wait cannot observe the elevated program's exit code on Windows.

Python API

from py_admin_launch import launch

launch(["python", "-m", "http.server", "80"])

launch() accepts a command list plus optional cwd and wait arguments:

result = launch(["your-command", "arg1"], cwd="/tmp", wait=True)
print(result.elevated, result.returncode)

When wait=True, returncode is the launched command's exit code where the platform exposes one. When wait=False, returncode is None.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_admin_launch-0.1.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_admin_launch-0.1.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file py_admin_launch-0.1.1.tar.gz.

File metadata

  • Download URL: py_admin_launch-0.1.1.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10

File hashes

Hashes for py_admin_launch-0.1.1.tar.gz
Algorithm Hash digest
SHA256 91ce787877c0d372d32732eca1a4b3aebeb9c4a8555a97d487dcd9c53a7096ea
MD5 d07befc7ebe9ab21aa9c15ae79fdd4d7
BLAKE2b-256 7c38d8326e9b5b8496b28069d85c89516f02cda2a2ae178bc15e90f0e7cc8bf6

See more details on using hashes here.

File details

Details for the file py_admin_launch-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: py_admin_launch-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10

File hashes

Hashes for py_admin_launch-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 50dbe879bce05be8a7698e8601e9a386d6b89a141eeccf6d4e8810242d0fb882
MD5 c3e972c78526a5e96cb3c11195854725
BLAKE2b-256 b2947ae33ecd35cb9a89fcb0c72a85fb835b186fa77d39782e34d0c247aeba39

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page