Last active
September 24, 2023 03:11
-
-
Save TheJustLink/1f1707f971c81273339525558537c1e0 to your computer and use it in GitHub Desktop.
Easy sudo in Windows CMD/PowerShell -> with multiple commands support through sudo args
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| SetLocal EnableDelayedExpansion | |
| set argument=%* | |
| set argument=!argument:"="! | |
| set argument=!argument:'=''! | |
| set firstSymbol=%argument:~0,1% | |
| set checkSymbol=" | |
| if !firstSymbol! == !checkSymbol! ( | |
| set argument=!argument:~1,-1! | |
| ) | |
| powershell -Command "Start-Process cmd -ArgumentList(('/k cd {0}' -f (Get-Location).path), '& !argument!') -Verb RunAs" | |
| exit |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add sudo.cmd to PATH and use anywhere you want
Examples: