Use runas with cmd /k and path containing spaces

Here is the command I try to execute:

runas /netonly /user:DOMAIN\user "cmd /k C:\Program Files (x86)\program.exe"

When i try to execute it I have the following error message:
'C:\Program' is not recognized as an internal or external command, operable program or batch file.

As the following commands work:

runas /netonly /user:DOMAIN\user "C:\Program Files (x86)\program.exe"
cmd /k """C:\Program Files (x86)\program.exe"""

I also try this command:

runas /netonly /user:DOMAIN\user "cmd /k """"""C:\Program Files (x86)\program.exe"""""""
# bad syntax
runas /netonly /user:DOMAIN\user "cmd /k \"C:\Program Files (x86)\program.exe\""
# The term 'x86' is not recognized

I didn't manage to find the right used of double quotes to make my command run.

1 Answer

One way is to use the short pathname, e.g.

runas /netonly /user:DOMAIN\user "cmd /k C:\Progra~2\program.exe"

dir /x will give both the short and the long filename.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like