How to execute 2 commands inside a single runas?

2

  1. When executed independently, they execute perfectly.
  2. When executed in 2 consecutive runas statements, chrome.exe is executed before robocopy has had a chance to finish.
  3. When placed inside a single runas separated by a &, it will not execute properly. Why?
 runas /savecred /user:chrome "robocopy C:\Users\chrome\AppData\Local\Google\Chrome-Backup C:\Users\chrome\AppData\Local\Google\Chrome /mir & \"!ProgramFiles(x86)!\Google\Chrome\Application\chrome.exe\""

stephenson

Posted 2016-04-02T15:43:49.870

Reputation: 41

What is !ProgramFiles(x86)!? Should that be %ProgramFiles(x86)%? Or is this part of a batch file using delayed expansion? – DavidPostill – 2016-04-03T11:30:08.503

What do you mean "it will not execute properly". What does it do? – Wes Larson – 2016-04-08T20:53:19.583

Answers

0

As far as I can tell, runas will only take one command.

You can, however, work around this by making a batch file of your multiple commands, and then using runas to execute your batch file. Like this:

REM This file is CopyChromeStuffAndRunIt.bat

robocopy "C:\Users\chrome\AppData\Local\Google\Chrome-Backup" "C:\Users\chrome\AppData\Local\Google\Chrome" /mir
"%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe\"

Then run your command:

runas /savecred /user:chrome "c:\batFileLocation\CopyChromeStuffAndRunIt.bat"

Alternatively, instead of running your command from the command line, you could put the runas command in another, separate batch file, so that you end up with two batch files.

Wes Larson

Posted 2016-04-02T15:43:49.870

Reputation: 244

0

Your first idea to use the & to stick two commands together is the right way.

Use this sticked command and put it on a cmd like follows:

Runas /savecred /user:chrome "cmd /c ""robocopy C:\Users\chrome\AppData\Local\Google\Chrome-Backup C:\Users\chrome\AppData\Local\Google\Chrome /mir & \"!ProgramFiles(x86)!\Google\Chrome\Application\chrome.exe\"""

This allows you to execute more than one command in one runas statement without using batch files.

Clijsters

Posted 2016-04-02T15:43:49.870

Reputation: 208