From a7338f638c43afb536d4d19d502ff5157395c91d Mon Sep 17 00:00:00 2001 From: Joran Dirk Greef Date: Tue, 20 Jun 2017 10:03:07 +0200 Subject: [PATCH] Escape ampersand and other characters special to PowerShell --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index cb56ac7..1893a32 100644 --- a/index.js +++ b/index.js @@ -458,7 +458,13 @@ function WindowsElevate(instance, end) { // var command = 'cscript.exe //NoLogo "' + instance.pathElevate + '"'; var command = []; command.push('powershell.exe'); - command.push('Start-Process "' + instance.pathExecute + '"'); + command.push('Start-Process'); + command.push('-FilePath'); + // Escape characters for cmd using double quotes: + // Escape characters for PowerShell using single quotes: + // Escape single quotes for PowerShell using backtick: + // See: https://ss64.com/ps/syntax-esc.html + command.push('"\'' + instance.pathExecute.replace(/'/g, "`'") + '\'"'); command.push('-WindowStyle hidden'); command.push('-Verb runAs'); command = command.join(' ');