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:
pkexecfor polkit GUI authentication, falling back tosudowhenpkexecis not available. - Windows:
ShellExecuteW(..., "runas", ...). - macOS:
osascript+with administrator privileges, falling back tosudowhenosascriptis 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91ce787877c0d372d32732eca1a4b3aebeb9c4a8555a97d487dcd9c53a7096ea
|
|
| MD5 |
d07befc7ebe9ab21aa9c15ae79fdd4d7
|
|
| BLAKE2b-256 |
7c38d8326e9b5b8496b28069d85c89516f02cda2a2ae178bc15e90f0e7cc8bf6
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50dbe879bce05be8a7698e8601e9a386d6b89a141eeccf6d4e8810242d0fb882
|
|
| MD5 |
c3e972c78526a5e96cb3c11195854725
|
|
| BLAKE2b-256 |
b2947ae33ecd35cb9a89fcb0c72a85fb835b186fa77d39782e34d0c247aeba39
|