Thursday, April 27, 2017

Starting programs with quoted arguments from a PowerShell subprocess may take a lot of quoting

One user wanted to launch an elevated (but not as the current user) MMC window with a certain console file whose path contains spaces. Their strategy was to use PowerShell to launch a PowerShell process as a different user that then ran MMC with administrative privilege and the target console file. The problem was that MMC couldn't open the file because the part of the path after the space got cut off; the quoting didn't help.

I don't know all the rules for escaping, so my first strategy was to just keep adding extra quotes to escape the existing quotes. That eventually worked, but it took nine quote characters on each side of the argument, instead of the three that the question author had tried.

start-process powershell 'start-process mmc.exe """""""""c:\administrative tool\console1.msc""""""""" -verb runas' -credential domain\user

No comments:

Post a Comment