How do I open a elevated command prompt using command lines on a normal cmd?
For example, I use runas /username:admin cmd
but the cmd that was opened do
I don't have enough reputation to add a comment to the top answer, but with the power of aliases you can get away with just typing the following:
powershell "start cmd -v runAs"
This is just a shorter version of user3018703 excellent solution:
powershell -Command "Start-Process cmd -Verb RunAs"
sudo.bat
(you can replace sudo
with any name you want) with following content
powershell.exe -Command "Start-Process cmd \"/k cd /d %cd%\" -Verb RunAs"
sudo.bat
to a folder in your PATH
; if you don't know what that means, just move these files to c:\windows\
sudo
will work in Run dialog (win+r) or in explorer address bar (this is the best part :))sudo.bat
(you can replace sudo
with any name you want) with following content
nircmdc elevate cmd /k "cd /d %cd%"
nircmdc.exe
and sudo.bat
to a folder in your PATH
; if you don't know what that means, just move these files to c:\windows\
sudo
will work in Run dialog (win+r) or in explorer address bar (this is the best part :))Make the batch file save the credentials of the actual administrator account by using the /savecred
switch. This will prompt for credentials the first time and then store the encrypted password in credential manager. Then for all subsequent times the batch runs it will run as the full admin but not prompt for credentials because they are stored encrypted in credential manager and the end user is unable to get the password. The following should open an elevated CMD with full administrator privileges and will only prompt for password the first time:
START c:\Windows\System32\runas.exe /user:Administrator /savecred cmd.exe
I've been using Elevate for awhile now.
It's description - This utility executes a command with UAC privilege elevation. This is useful for working inside command prompts or with batch files.
I copy the bin.x86-64\elevate.exe
from the .zip
into C:\Program Files\elevate
and add that path to my PATH
.
Then GitBash I can run something like elevate sc stop W3SVC
to turn off the IIS
service.
Running the command gives me the UAC
dialog, properly focused with keyboard control and upon accepting the dialog I return to my shell.
There are several ways to open an elevated cmd, but only your method works from the standard command prompt. You just need to put user
not username
:
runas /user:machinename\adminuser cmd
See relevant help from Microsoft community.