在Javascript中运行命令Wscript

在Javascript中运行命令Wscript

本文介绍了在Javascript中运行命令Wscript.shell ActiveX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,需要通过一些参数来运行ActiveX程序。

我用下面的JavaScript获得这些参数:

I have a webpage that needs to run a program by ActiveX with some parameters.
I get those parameters with the following bit of JavaScript:

var var1 = getUrlParameter("par1", false);
var var2 = getUrlParameter("par2", false);
var var3 = getUrlParameter("par3", true);
var var4 = getUrlParameter("par4", true);

我正在创建一个新的ActiveX对象:

I'm creating a new ActiveX Object:

MyObject = new ActiveXObject("WScript.Shell")

然后我需要运行一个命令,我已经尝试了几个带有双引号和单引号的选项,但没有任何作用。有时程序根本没有启动,有时变量没有通过。
我试过了:

Then I need to run a command, I've tried several options with double and single quotes but nothing works. Sometimes the program isn't started at all, sometimes the variables aren't getting through.I've tried:

MyObject.Run(""C:\\Path with\\some spaces\\program.exe" D:\\pathtoafile /PARAM:/para1="+var1+"\,/para2="+var2+"\,/para3="+var3+"\,/para4=\""+var4+"\"");
MyObject.Run('"C:\\Path with\\some spaces\\program.exe" D:\\pathtoafile /PARAM:/para1="+var1+"\,/para2="+var2+"\,/para3="+var3+"\,/para4=\""+var4+"\"');
MyObject.Run("'C:\\Path with\\some spaces\\program.exe' D:\\pathtoafile /PARAM:/para1="+var1+"\,/para2="+var2+"\,/para3="+var3+"\,/para4=\""+var4+"\"");


推荐答案

/ p>

After some more hours of trying if found it!

MyObject.Run('"C:\\Path with\\some spaces\\program.exe"' + " " + "D:\\pathtoafile" + " " +  "/PARAM:/para1="+var1+"\,/para2="+var2+"\,/para3="+var3+"\,/para4=\""+var4+"\"");

这篇关于在Javascript中运行命令Wscript.shell ActiveX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 15:02