Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run commands in cmd [elevated] using PowerShell?

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?

like image 724
prince skosana Avatar asked Jun 09 '26 08:06

prince skosana


1 Answers

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.

like image 74
mklement0 Avatar answered Jun 11 '26 20:06

mklement0