I wanted to call MSIEXEC to install my program on another user's machines, and on top of that, I needed to use an admin's login to do so. In the past I would have remote desktopped into the machine while the user was logged off; this time I thought I'd investigate RUNAS as a possible solution.
The basic command line for MSIEXEC (the command-line version of Windows installer) is:
msiexec /i "\\server\path\installer package.msi"
Note the quotes around the MSI package, which are necessary as the path to the MSI package has spaces in it.
The basic command line for RUNAS is:
runas /user:domain\username "program"
...where "program" refers to the command to be run, which must have quotes around it if it has spaces. Since the "program" I want to run is the command line to MSIEXEC that itself has quotes, the quotes in the MSIEXEC call need to be escaped, like so:
runas /user:domain\username "msiexec /i \"\\server\path\installer package.msi\" "
Putting a backslash in front of the quotes inside the RUNAS quotes (e.g. the MSIEXEC call quotes around the MSI package) escapes them and allows "nested" quotes.
The alternatives of using a single quote/apostrophe around the MSI package will make the Windows Installer command fail, and using double quotes ("") around the MSI package will produce a RUNAS error.