How to open an elevated cmd using command line for Windows?

后端 未结 23 1565
既然无缘
既然无缘 2020-12-04 06:21

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

23条回答
  •  自闭症患者
    2020-12-04 06:28

    While both solutions provided by Dheeraj Bhaskar work, unfortunately they will result in the UAC dialog showing up on top (z-order-wise) but not getting focused (the focused window is the caller cmd/powershell window), thus I either need to grab the mouse and click "yes", or to select the UAC window using Alt+Shift+Tab. (Tested on Win10x64 v1607 build14393.447; UAC = "[...] do not dim [...]".)

    The following solution is a bit awkward as it uses two files, but it preserves the correct focus order, so no extra mouse / keyboard actions are required (besides confirming the UAC dialog: Alt+Y).

    1. cmdadm.lnk (shortcut properties / Advanced... / Run as administrator = ON) %SystemRoot%\System32\cmd.exe /k "cd /d"
    2. su.bat @start cmdadm.lnk %cd%

    Run with su.

提交回复
热议问题