问题描述
我有一个Intranet Web应用程序需要运行一些外部应用程序,如Word,记事本和其他特定的应用程序...我的代码允许访问IE(ActiveX)和Firefox(XPCOM)。当我使用整个路径(如C:\ windows \\\otepad.exe),我可以在两个浏览器运行,但问题是:有很多版本的一些应用程序,如Microsoft Word(2003,2007,2010 ...),并且本地路径总是不同的,但是如果我在Windows中使用Run ...选项,除了版本之外,我只能输入winword.exe和MS Word加载。如果我只通过IE浏览器的文件名到ActiveX,我可以打电话给MS Word,但是在Firefox中,用XPCOM,我不是。所以,我的问题是:有没有办法使XPCOM代码运行MS Word只是与它的相对路径(文件名)?我测试了整个方法,但没有成功。
这是我的代码:
pre $ function $ RunExe(path){
尝试{
var ua = navigator.userAgent.toLowerCase();
if(ua.indexOf(msie)!= -1){
MyObject = new ActiveXObject(WScript.Shell)
MyObject.Run(path);
} else {
netscape.security.PrivilegeManager.enablePrivilege(UniversalXPConnect);
var exe = window.Components.classes ['@ mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
exe.initWithPath(path);
var run = window.Components.classes ['@ mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess);
run.init(exe);
var parameters = [];
run.run(false,parameters,parameters.length);
} catch(ex){
alert(ex.toString());
code
$ b
这个调用是这样的: p>
< a href =#onclick =javascript:RunExe('winword.exe');> Open Word< / A>
任何帮助将不胜感激。谢谢。
我相信你的问题在于IE直接与Windows一起工作, -平台。假设你只想在Windows上工作,你可以执行命令提示符。
C:\ Windows \ System32 \ cmd.exe
并传递一个参数如$ /
启动winword.exe
然后执行和Run一样。
I have an intranet web application who needs to run some external applications, like Word, Notepad and other particular ones... My code allow the access with IE (ActiveX) and Firefox (XPCOM). When I use the whole path (like "C:\windows\notepad.exe") I can run in both browses, but y problem is: there's a lot of versions for some applications like Microsoft Word (2003, 2007, 2010...), and the local path is always different, BUT if I use the "Run..." option in Windows, I can only type "winword.exe" and MS Word loads, besides it's version. If I pass only the filename to ActiveX in IE, I'm able to call MS Word, but in Firefox, with XPCOM, I'm not. So, my question is: Is there any way to make the XPCOM code run MS Word just with it's relative path (filename)? I've tested a whole of ways but without success.
Here's my code:
function RunExe(path) {
try {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf("msie") != -1) {
MyObject = new ActiveXObject("WScript.Shell")
MyObject.Run(path);
} else {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var exe = window.Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
exe.initWithPath(path);
var run = window.Components.classes['@mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess);
run.init(exe);
var parameters = [""];
run.run(false, parameters, parameters.length);
}
} catch (ex) {
alert(ex.toString());
}
}
And the call has been made like this:
<a href="#" onclick="javascript:RunExe('winword.exe');">Open Word</a>
Any help would be appreciated. Thank you.
I believe your problem lies in the fact that IE directly works with Windows where as Firefox is intended to be cross-platform. Assuming you only want this to work on Windows, you could execute the command prompt
C:\Windows\System32\cmd.exe
and pass it an argument like
start winword.exe
Then it will perform in the same manner as Run.
这篇关于如何用Javascript / XPCOM打开.EXE作为Windows“Run ...”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!