1

I have a VB script that takes in several parameters that could include spaces using cscript, and I make the call using:

nsExec::exec 'cscript.exe "$PATH_TO_FILE\program.vbs" "Something with spaces" "Something else"'

Now, I want one of the "Something else" strings to include a double quote character, where the string is

Something " else.

I have tried

nsExec::exec 'cscript.exe "$PATH_TO_FILE\program.vbs" "Something with spaces" "Something "" else."'

with an escaped " but that did not work, it simply used "Something else" as the string passed in.

jkh
  • 3,618
  • 8
  • 38
  • 66

2 Answers2

0

You can read the entire process command line as one string like this (JScript code, sorry):

// Read process command line
var WshShell = WScript.CreateObject("WScript.Shell");
var objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");
var childProcess =
    WshShell.Exec
    (
        '"' + WshShell.Environment('PROCESS')('ComSpec') + '"'
        +
        " /C Echo \"Text lines\" && Set /p VarName="
    );
childProcess.StdOut.ReadLine();
var current_pid =
    objWMIService.ExecQuery
        (
        "Select * From Win32_Process Where ProcessId=" + childProcess.ProcessID
        );
current_pid = (new Enumerator(current_pid)).item().ParentProcessId;
if (current_pid)
{
    childProcess.StdIn.WriteLine("value");  // child process should now exit
}
else
{
    WScript.StdErr.WriteLine("Get current PID from WMI failed.");
    WScript.Quit(7);
}

var cmd_line = objWMIService.ExecQuery("Select * From Win32_Process Where ProcessID=" + current_pid);

cmd_line = (new Enumerator(cmd_line)).item().CommandLine;
WScript.Echo(cmd_line);

but than you will have to parse the string into separate arguments yourself.

Toughy
  • 767
  • 6
  • 5
0

Basically, there is not a way to deal with these quotes, so you need a workaround (use QUOTE and then replace in program with a ').

jkh
  • 3,618
  • 8
  • 38
  • 66