Open notepad and paste this code:
@echo off
powershell -Command "Start-Process cmd -Verb RunAs -ArgumentList '/c %*'"
@echo on
Then, save the file as sudo.cmd
. Copy this file and paste it at C:\Windows\System32
or add the path where sudo.cmd
is to your PATH Environment Variable.
When you open command prompt, you can now run something like sudo start .
.
If you want the terminal 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 %*'"
@echo on
Explanation:
powershell -Command
runs a powershell command.
Start-Process
is a powershell command that starts a process, in this case, command prompt.
-Verb RunAs
runs the command as admin.
-Argument-List
runs the command with arguments.
Our arguments are '/c %*'
. %*
means all arguments, so if you did sudo foo bar
, it would run in command prompt foo bar
because the parameters are foo and bar, and %*
returns foo bar
.
The /c
is a cmd parameter for closing the window after the command is finished, and the /k
is a cmd parameter for keeping the window open.
runas /user:domain\username cmd.exe
I had to run it like this:runas /netonly /user:domain\username cmd.exe
– Hypotenuse