3

I run exe from my asp.net with JavaScript using ActiveXObject. It runs successfully, except parameters:

function CallEXE() {
  var oShell = new ActiveXObject("Shell.Application");
  var prog = "C:\\Users\\admin\\Desktop\\myCustom.exe";                 
  oShell.ShellExecute(prog,"customer name fullname","","open","1");
}

Example, I pass that like parameters,[1] customer name,[2] fullname, but after space character, Javascript perceive different parameter.

How can I fix?

enginocal
  • 309
  • 1
  • 5
  • 19

2 Answers2

1

ShellExecute takes the 2nd parameter to be a string that represents all the arguments and processes these using normal shell processing rules: spaces and quotes, in particular.

oShell.ShellExecute(prog,"customer name fullname",...)

In this case the 3 parameters that are passed are customer, name, fullname

oShell.ShellExecute(prog,"customer 'a name with spaces' fullname",...)

As corrected/noted by Remy Lebeau - TeamB, double-quotes can be used to defined argument boundaries:

oShell.ShellExecute(prog,'customer "a name with spaces" fullname',...)

In this case the 3 parameters that are passed are customer, a name with spaces, fullname

That is, think of how you would call myCustom.exe from the command-prompt. It's the same thing when using ShellExecute.

Happy coding.

  • Thanks @pst,but it still different parameter :) – enginocal Dec 21 '11 at 21:26
  • @engcmreng Aww :( What do you end up with? –  Dec 21 '11 at 21:29
  • 1
    Wrap the parameter value with spaces using double-quotes instead of single-quotes, eg: `oShell.ShellExecute(prog, "customer \"a name with spaces\" fullname",...)` or `oShell.ShellExecute(prog, 'customer "a name with spaces" fullname',...)`. – Remy Lebeau Dec 21 '11 at 21:42
0

Try escaping your spaces with a backslash. The cmd.exe cd command does this, maybe you'll get lucky and it'll work here as well...

oShell.ShellExecute(prog,"customer a\ name\ with\ spaces fullname", ...)
cfeduke
  • 23,100
  • 10
  • 61
  • 65