Open notepad and paste this code:
@echo off powershell -Command "Start-Process cmd -Verb RunAs -ArgumentList '/c cd /d %CD% && %*''" @echo onThen, save the file as
sudo.cmd. Copy this file and paste it atC:\Windows\System32or add the path wheresudo.cmdis to your PATH Environment Variable.When you open command prompt, you can now run something like
sudo start ..If you want the admin command prompt window to stay open when you run the command, change the code in notepad to this:
@echo off powershell -Command "Start-Process cmd -Verb RunAs -ArgumentList '/k cd /d %CD% && %*'" @echo onExplanation:
powershell -Commandruns a powershell command.
Start-Processis a powershell command that starts a process, in this case, command prompt.
-Verb RunAsruns the command as admin.
-Argument-Listruns the command with arguments.Our arguments are
'/c cd /d %CD% && %*'.%*means all arguments, so if you didsudo foo bar, it would run in command promptfoo barbecause the parameters are foo and bar, and%*returnsfoo bar.cd /d %CD%is a command to go to the current directory. This will ensure that when you open the elevated window, the directory will be the same as the normal window. the&&means that if the first command is successful, run the second command.The
/cis a cmd parameter for closing the window after the command is finished, and the/kis a cmd parameter for keeping the window open.Credit to Adam Plocher for the staying in the current directory code.
Search This Blog
Wednesday, 8 April 2020
sudo windows
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment