Search code examples
vbscriptescapingargumentscommand-line-argumentsrunas

runas does not allow complex arguments?


I have an app that I'm trying to run elevated on windows 7 and windows xp thin clients but I cant seem to get the runas.exe cmd line correct. I know I need the backslash escape character in there so runas interprets the spaces correctly. This works when sending runas a single argument that has been escaped with a backslash. This scenario is all I found as a solution and it works however, I need to send multiple arguments that are all escaped with backslashes because of spaces in the arguements due to file paths, etc. Here are some examples:

These work And as expected will prompt for the administrator password:

runas.exe /user:Administrator "C:\update_andon.exe autosetup /kiosktype:\"Andon Kiosk"\

runas.exe /user:Administrator "C:\update_andon.exe autosetup /directory:\"C:\Program Files\CIMS_Andon\Kiosk"\

When I start adding the rest of the arguments I need such as the line below, I receive the runas help text indicating there was an issue:

runas.exe /user:administrator "C:\update_andon.exe autosetup /kiosktype:\"Andon Kiosk"\ /exename:\"eAndonKiosk.exe"\ /directory:\"C:\Program Files\CIMS_Andon\Kiosk"\ /repository:\"\\domain\sat\shared\repository\andon kiosk"\"

One solution is to run each argument at a time one after the other but I dont see this as a solution as much as it is a workaround. Am I missing something with the way I have the backslashes mixed in with the various arguments? Am I missing more quotes somewhere?

Thanks


Solution

  • Canonical solution: write the command to a batch script and run the script via runas.