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

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

    ..

    @ECHO OFF
    SETLOCAL EnableDelayedExpansion EnableExtensions
    NET SESSION >nul 2>&1
    IF %ERRORLEVEL% NEQ 0 GOTO ELEVATE
    GOTO :EOF
    
    :ELEVATE
    SET this="%CD%"
    SET this=!this:\=\\!
    
    MSHTA "javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute('CMD', '/K CD /D \"!this!\"', '', 'runas', 1);close();"
    EXIT 1
    

    save this script as "god.cmd" in your system32 or whatever your path is directing to....

    if u open a cmd in e:\mypictures\ and type god it will ask you for credentials and put you back to that same place as the administrator...

提交回复
热议问题