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

后端 未结 23 1568
既然无缘
既然无缘 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:46

    Here is a way to integrate with explorer. It will popup a extra menu item when you right-click in any folder within Windows Explorer:

    Here are the steps:

    1. Create this key: \HKEY_CLASSES_ROOT\Folder\shell\dosherewithadmin
    2. Change its Default value to whatever you want to appear as the menu item text. Ex "DOS Shell as Admin"
    3. Create this another key: \HKEY_CLASSES_ROOT\Folder\shell\dosherewithadmin\command
    4. Change its default value to this, ipsis litteris: powershell.exe -Command "Start-Process -Verb RunAs 'cmd.exe' -Args '/k pushd "%1"'"
    5. It's done. Now right-click in any folder and you will see your item there within the other items.

    *Use pushd instead of cd to allow it to work in any drive. :-)

提交回复
热议问题