# sudo-win32
This missing sudo command for win32. This is a thin wrapper over `gsudo`. Check out the excellent repo [here](https://github.com/gerardog/gsudo).
The only benefit for this repo is that you don't need administrator privledges in order to use this tool, while using
something like choco install `gsudo` requires admin privledges. stderr/stdout and process return values are all supported.
If you want to use `gsudo` directly, you can install it with `choco install gsudo`.
The most recent `gsudo` version used is `2.0.4`
[![Linting](https://github.com/zackees/sudo-win32/actions/workflows/lint.yml/badge.svg)](https://github.com/zackees/sudo-win32/actions/workflows/lint.yml)
[![Tests](https://github.com/zackees/sudo-win32/actions/workflows/push_win.yml/badge.svg)](https://github.com/zackees/sudo-win32/actions/workflows/push_win.yml)
# Usage
```bash
> pip install sudo_win32[sudo]
> sudo taskkill /F /im wslservice.exe
```
If you omit [sudo] then the command will just be `sudo_win32`.
# Documentation
This is shamelessly ripped from the `gsudo` repo and is kept as-is. Simply replace `gsudo` with
`sudo_win32` or `sudo` if you installed with the [sudo] extra. Otherwise it's the same.
## Usage
``` powershell
gsudo [options] # Elevates your current shell
gsudo [options] {command} [args] # Runs {command} with elevated permissions
gsudo cache [on | off | help] # Starts/Stops a credentials cache session. (less UAC popups)
gsudo status # Shows current user, cache and console status.
gsudo !! # Re-run last command as admin. (YMMV)
```
``` powershell
New Window options:
-n | --new # Starts the command in a new console/window (and returns immediately).
-w | --wait # When in new console, wait for the command to end.
--keepShell # After running a command, keep the elevated shell open.
--keepWindow # After running a command in a new console, ask for keypress before closing the console/window.
Security options:
-u | --user {usr} # Run as the specified user. Asks for password. For local admins shows UAC unless '-i Medium'
-i | --integrity {v} # Specify integrity level: Untrusted, Low, Medium, MediumPlus, High (default), System
-s | --system # Run as Local System account (NT AUTHORITY\SYSTEM).
--ti # Run as member of NT SERVICE\TrustedInstaller
-k # Kills all cached credentials. The next time gsudo is run a UAC popup will be appear.
Shell related options:
-d | --direct # Skips Shell detection. Asume CMD shell or CMD {command}.
--loadProfile # When elevating PowerShell commands, load user profile.
Other options:
--loglevel {val} # Set minimum log level to display: All, Debug, Info, Warning, Error, None
--debug # Enable debug mode.
--copyns # Connect network drives to the elevated user. Warning: Verbose, interactive asks for credentials
--copyev # (deprecated) Copy environment variables to the elevated process. (not needed on default console mode)
```
**Note:** You can use anywhere **the `sudo` alias** created by the installers.
**Examples:**
``` powershell
gsudo # elevates the current shell in the current console window (Supports Cmd/PowerShell/Pwsh Core/Yori/Take Command/git-bash/cygwin)
gsudo -n # launch the current shell elevated in a new console window
gsudo -n -w powershell ./Do-Something.ps1 # launch in new window and wait for exit
gsudo notepad %windir%\system32\drivers\etc\hosts # launch windows app
sudo notepad # sudo alias built-in
# redirect/pipe input/output/error example
gsudo dir | findstr /c:"bytes free" > FreeSpace.txt
gsudo config LogLevel "Error" # Configure Reduced logging
gsudo config Prompt "$P [elevated]$G " # Configure a custom Elevated Prompt
gsudo config Prompt --reset # Reset to default value
# Enable credentials cache (less UAC popups):
gsudo config CacheMode Auto
```
# Development
To develop software, run `. ./activate.sh`
# Windows
This environment requires you to use `git-bash`.
# Linting
Run `./lint.sh` to find linting errors using `pylint`, `flake8` and `mypy`.
# Release Notes
* 1.0.9 - Allow strings or list[str] as command.
* 1.0.8 - Fixes some commands in admin mode.
* 1.0.7 - Use shell mode for gsudo, since it's a better experience. Commands are merged via subprocess.list2cmdline
* 1.0.6 - Switch the implementation to `gsudo`, which is excellent and does everything this lib needs.
* 1.0.5 - sudo-win32[sudo] now works correctly, before it was unconditionally installing.
* 1.0.3 - The stdout/stderr are now correct re-routed back.
* 1.0.2 - The return value of the command is now returned when elevating privledges.
* 1.0.1 - Fixing the readme
* 1.0.0 - Initial release
Raw data
{
"_id": null,
"home_page": "https://github.com/zackees/sudo-win32",
"name": "sudo-win32",
"maintainer": "Zachary Vorhies",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "template-python-cmd",
"author": "",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/f7/1c/87c9aceb00d99829c351cc61cbd1a2d0006db69bcf158b4f4487c185f571/sudo-win32-1.0.9.tar.gz",
"platform": null,
"description": "# sudo-win32\r\n\r\nThis missing sudo command for win32. This is a thin wrapper over `gsudo`. Check out the excellent repo [here](https://github.com/gerardog/gsudo).\r\n\r\nThe only benefit for this repo is that you don't need administrator privledges in order to use this tool, while using\r\nsomething like choco install `gsudo` requires admin privledges. stderr/stdout and process return values are all supported.\r\nIf you want to use `gsudo` directly, you can install it with `choco install gsudo`.\r\n\r\nThe most recent `gsudo` version used is `2.0.4`\r\n\r\n\r\n[![Linting](https://github.com/zackees/sudo-win32/actions/workflows/lint.yml/badge.svg)](https://github.com/zackees/sudo-win32/actions/workflows/lint.yml)\r\n[![Tests](https://github.com/zackees/sudo-win32/actions/workflows/push_win.yml/badge.svg)](https://github.com/zackees/sudo-win32/actions/workflows/push_win.yml)\r\n\r\n# Usage\r\n\r\n```bash\r\n> pip install sudo_win32[sudo]\r\n> sudo taskkill /F /im wslservice.exe\r\n```\r\n\r\nIf you omit [sudo] then the command will just be `sudo_win32`.\r\n\r\n# Documentation\r\n\r\nThis is shamelessly ripped from the `gsudo` repo and is kept as-is. Simply replace `gsudo` with\r\n`sudo_win32` or `sudo` if you installed with the [sudo] extra. Otherwise it's the same.\r\n\r\n## Usage\r\n\r\n``` powershell\r\ngsudo [options] # Elevates your current shell\r\ngsudo [options] {command} [args] # Runs {command} with elevated permissions\r\ngsudo cache [on | off | help] # Starts/Stops a credentials cache session. (less UAC popups)\r\ngsudo status # Shows current user, cache and console status.\r\ngsudo !! # Re-run last command as admin. (YMMV)\r\n```\r\n\r\n``` powershell\r\nNew Window options:\r\n -n | --new # Starts the command in a new console/window (and returns immediately).\r\n -w | --wait # When in new console, wait for the command to end.\r\n --keepShell # After running a command, keep the elevated shell open.\r\n --keepWindow # After running a command in a new console, ask for keypress before closing the console/window.\r\n\r\nSecurity options:\r\n -u | --user {usr} # Run as the specified user. Asks for password. For local admins shows UAC unless '-i Medium'\r\n -i | --integrity {v} # Specify integrity level: Untrusted, Low, Medium, MediumPlus, High (default), System\r\n -s | --system # Run as Local System account (NT AUTHORITY\\SYSTEM).\r\n --ti # Run as member of NT SERVICE\\TrustedInstaller\r\n -k # Kills all cached credentials. The next time gsudo is run a UAC popup will be appear.\r\n\r\nShell related options:\r\n -d | --direct # Skips Shell detection. Asume CMD shell or CMD {command}.\r\n --loadProfile # When elevating PowerShell commands, load user profile.\r\n\r\nOther options:\r\n --loglevel {val} # Set minimum log level to display: All, Debug, Info, Warning, Error, None\r\n --debug # Enable debug mode.\r\n --copyns # Connect network drives to the elevated user. Warning: Verbose, interactive asks for credentials\r\n --copyev # (deprecated) Copy environment variables to the elevated process. (not needed on default console mode)\r\n```\r\n\r\n**Note:** You can use anywhere **the `sudo` alias** created by the installers.\r\n\r\n**Examples:**\r\n\r\n``` powershell\r\ngsudo # elevates the current shell in the current console window (Supports Cmd/PowerShell/Pwsh Core/Yori/Take Command/git-bash/cygwin)\r\ngsudo -n # launch the current shell elevated in a new console window\r\ngsudo -n -w powershell ./Do-Something.ps1 # launch in new window and wait for exit\r\ngsudo notepad %windir%\\system32\\drivers\\etc\\hosts # launch windows app\r\n\r\nsudo notepad # sudo alias built-in\r\n\r\n# redirect/pipe input/output/error example\r\ngsudo dir | findstr /c:\"bytes free\" > FreeSpace.txt\r\n\r\ngsudo config LogLevel \"Error\" # Configure Reduced logging\r\ngsudo config Prompt \"$P [elevated]$G \" # Configure a custom Elevated Prompt\r\ngsudo config Prompt --reset # Reset to default value\r\n\r\n# Enable credentials cache (less UAC popups):\r\ngsudo config CacheMode Auto\r\n```\r\n\r\n\r\n# Development\r\n\r\nTo develop software, run `. ./activate.sh`\r\n\r\n# Windows\r\n\r\nThis environment requires you to use `git-bash`.\r\n\r\n# Linting\r\n\r\nRun `./lint.sh` to find linting errors using `pylint`, `flake8` and `mypy`.\r\n\r\n# Release Notes\r\n * 1.0.9 - Allow strings or list[str] as command.\r\n * 1.0.8 - Fixes some commands in admin mode.\r\n * 1.0.7 - Use shell mode for gsudo, since it's a better experience. Commands are merged via subprocess.list2cmdline\r\n * 1.0.6 - Switch the implementation to `gsudo`, which is excellent and does everything this lib needs.\r\n * 1.0.5 - sudo-win32[sudo] now works correctly, before it was unconditionally installing.\r\n * 1.0.3 - The stdout/stderr are now correct re-routed back.\r\n * 1.0.2 - The return value of the command is now returned when elevating privledges.\r\n * 1.0.1 - Fixing the readme\r\n * 1.0.0 - Initial release\r\n",
"bugtrack_url": null,
"license": "BSD 3-Clause License",
"summary": "The missing sudo command for win32",
"version": "1.0.9",
"split_keywords": [
"template-python-cmd"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8647cdadfdeec0dc6af6d7d95cf8539ed133c1c50eec342224e779243eeaea43",
"md5": "b6b78c356dc232be6ed45424f0832943",
"sha256": "faa6d30e8c5d5c73b2bba7775f047f8a33ffad9bce01ab88d7f29c609faf5e81"
},
"downloads": -1,
"filename": "sudo_win32-1.0.9-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "b6b78c356dc232be6ed45424f0832943",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.7",
"size": 4226782,
"upload_time": "2023-03-17T08:37:22",
"upload_time_iso_8601": "2023-03-17T08:37:22.437847Z",
"url": "https://files.pythonhosted.org/packages/86/47/cdadfdeec0dc6af6d7d95cf8539ed133c1c50eec342224e779243eeaea43/sudo_win32-1.0.9-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f71c87c9aceb00d99829c351cc61cbd1a2d0006db69bcf158b4f4487c185f571",
"md5": "747a67fc2e42ac835b4d86a07540f06d",
"sha256": "768b8ec8e824007cea3e163482cfc588f6e9806e2bd98f998e099e40eae0560e"
},
"downloads": -1,
"filename": "sudo-win32-1.0.9.tar.gz",
"has_sig": false,
"md5_digest": "747a67fc2e42ac835b4d86a07540f06d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 4219171,
"upload_time": "2023-03-17T08:37:30",
"upload_time_iso_8601": "2023-03-17T08:37:30.782961Z",
"url": "https://files.pythonhosted.org/packages/f7/1c/87c9aceb00d99829c351cc61cbd1a2d0006db69bcf158b4f4487c185f571/sudo-win32-1.0.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-17 08:37:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "zackees",
"github_project": "sudo-win32",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "sudo-win32"
}