gsudo,
An extremely useful and unique fully-featured wrapper of gsudo for python.
Introduction
Usage examples
Documentation
Introduction
This package was made to once and for all solve the common issue of rerunning python scripts and pyinstaller binaries as admin, and so much more! Even able to execute processes as SYSTEM or even TrustedInstaller! (SYSTEM is higher then admin, and TrustedInstaller is the highest privilege level on Windows machines!)
Take this example; if I have a script prints some useful info, that happens to need to be run as admin whenever it's called, but I don't want to always call it from an admin shell. The only way to solve this before was to run the script in as admin in a new window, but now all my useful information that our imaginary script just printed out is all in that new window! What to do? Well, by default on Windows, it is actually impossible to run a process as admin and keep its console output inside the same window. But not anymore! With functions such as gsudo.admin_subprocess.Popen() we can all have the best of both worlds!
Supports use with pyinstaller and other python packagers!
Can be installed with pip install gsudo
The git repository for this package can be found here. The docs also look nicer on github.
If you want to reach out, you may add me on discord at @z_h_ or join my server.
Usage examples
Re-running as admin and retaining console window:
import gsudo
# Are we admin? Lets find out.
print(gsudo.is_admin())
# If we're not, this script/executable will be re ran as admin, all the while retaining the same console window, as if by magic!
gsudo.rerun_as_admin(keep_same_console=True) # keeping the same console window is default behavior if not specified
# we can be confident that we will only get to this line once the script is running with admin.
print("Hey, I'm running as admin now!")
Running another script with the highest possible privileges:
import gsudo
gsudo.admin_subprocess.run('python another_script.py', run_as_TrustedInstaller=True) # the same high privilege arguments are available for the rerun function too
Documentation:
gsudo.rerun_as_admin()
gsudo.rerun_as_admin(run_as_SYSTEM=False, run_as_TrustedInstaller=False, keep_same_console=True)
By default, rerun the current script as admin. Optionally run as SYSTEM or even TrustedInstaller.
gsudo.admin_subprocess.Popen()
gsudo.admin_subprocess.Popen(command, run_as_SYSTEM=False, run_as_TrustedInstaller=False, **kwargs)
Works the exact same way as the beloved subprocess.Popen, but by default run the command as admin. Returns a subprocess "process" object, again, exactly the same as subprocess. Optionally run as SYSTEM or even TrustedInstaller.
gsudo.admin_subprocess.run()
gsudo.admin_subprocess.run(command, run_as_SYSTEM=False, run_as_TrustedInstaller=False, **kwargs)
Works the exact same way as subprocess.run, but by default run the command as admin. Returns a subprocess "process" object, again, exactly the same as subprocess. Optionally run as SYSTEM or even TrustedInstaller.
gsudo.is_admin()
gsudo.is_admin(simple=False)
Returns ints 0 if the current process isn't running as admin, returns 1 if the process is running with admin, returns 2 if the process is running as SYSTEM, and returns 3 if running as TrustedInstaller. On some machines it may return an incorrect result when running as SYSTEM or TrustedInstaller, but only inaccurate between those 2 selections.
if simple is set to True, then it will return False if not running with admin privileges or above, and True if it is.
Metadata
Release files for zhmiscellanygsudo 0.6.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zhmiscellanygsudo-0.6.8-py3-none-any.whl | Python 3 | none | any | Details for zhmiscellanygsudo-0.6.8-py3-none-any.whl |
Release files / zhmiscellanygsudo-0.6.8-py3-none-any.whl
| Download URL | zhmiscellanygsudo-0.6.8-py3-none-any.whl |
|---|---|
| Size | 3.6 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
90dd72d8ad18e9e4cf8fa5b10d4216a3038e5bf4750229d2d3c69b8e74fdd1ff
|
|
BLAKE2b-256 checksum How to use checksums |
2065b3b5251afe225cd8a77a0bc5b67459857e7b8ce6cc41a463110de91d2bc4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Security for zhmiscellanygsudo 0.6.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.