I want to run elevated command, for example calc.exe
in cmd using PowerShell. I've tried from PowerShell:
Start-Process -Verb RunAs cmd calc.exe
All it does is opening the elevated cmd, but does not run calc.exe
(command).
What am I doing wrong? Can someone help me?
The executable invoked by Start-Process
is cmd
; you must specify its arguments separately, via the -ArgumentList
( -Args
) parameter, as an array ( ,
-separated):
Start-Process -Verb RunAs cmd -Args /k, calc.exe
Note: The arguments happen not to need quoting here, but -
-prefixed arguments or arguments with embedded spaces do; quoting is always an option ( '/k', 'calc.exe'
)
Note:
/k
is required to keep the cmd
console window open after launching calc.exe
( /c
would close it right after, but in that case you could just skip cmd
and pass calc.exe
directly to Start-Process
).
Generally, you need either /c
or /k
in order to pass a command to execute to cmd
; without that, an argument such as calc.exe
is simply ignored .
Run cmd /?
for more information.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.