Skip to content

Instantly share code, notes, and snippets.

@TheJustLink
Last active September 24, 2023 03:11
Show Gist options
  • Select an option

  • Save TheJustLink/1f1707f971c81273339525558537c1e0 to your computer and use it in GitHub Desktop.

Select an option

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
@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
@TheJustLink

Copy link
Copy Markdown
Author

Add sudo.cmd to PATH and use anywhere you want

Examples:

sudo
sudo echo Hello World!
sudo "echo 1 & echo 2"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment