ActiveXObject(“Shell.Application”) - 如何传递带空格的参数?

发布于 2024-12-22 17:57:09 字数 392 浏览 2 评论 0原文

我使用 ActiveXObject 通过 JavaScript 从 asp.net 运行 exe。它运行成功,除了参数:

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

例如,我传递了类似的参数,[1]客户名称,[2]全名,但在空格字符之后,Javascript感知到不同的参数。

我该如何修复?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

桜花祭 2024-12-29 17:57:09

ShellExecute 将第二个参数作为表示所有 参数的字符串,并使用正常的 shell 处理规则(特别是空格和引号)处理这些参数。

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

在本例中,传递的 3 个参数是 customernamefullname

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

正如 Remy Lebeau - TeamB 所更正/指出的那样,双引号可用于定义参数边界:

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

在本例中,3 个参数是通过的是customer, a name with paths, fullname

也就是说,想想如何从命令提示符。使用 ShellExecute 时也是同样的情况。

快乐编码。

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.

初见终念 2024-12-29 17:57:09

尝试用反斜杠转义空格。 cmd.exe cd 命令执行此操作,也许您会很幸运,它也可以在这里工作...

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

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", ...)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文