3

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?

0

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.