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

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

    Can use a temporary environment variable to use with an elevated shortcut (

    start.cmd

    setx valueName_betterSpecificForEachCase %~dp0
    "%~dp0ascladm.lnk"
    

    ascladm.lnk (shortcut)

    _ properties\advanced\"run as administrator"=yes
    

    (to make path changes you'll need to temporarily create the env.Variable)

    _ properties\target="%valueName_betterSpecificForEachCase%\ascladm.cmd"
    
    _ properties\"start in"="%valueName_betterSpecificForEachCase%"
    

    ascladm.cmd

    setx valueName_betterSpecificForEachCase=
    reg delete HKEY_CURRENT_USER\Environment /F /V valueName_betterSpecificForEachCase
    "%~dp0fileName_targetedCmd.cmd"
    

    ) (targetedCmd gets executed in elevated cmd window)

    Although it is 3 files ,you can place everything (including targetedCmd) in some subfolder (do not forget to add the folderName to the patches) and rename "start.cmd" to targeted's one name

    For me it looks like most native way of doing this ,whilst cmd doesn't have the needed command

提交回复
热议问题