简体   繁体   English

如何使用 Javascript/XPCOM 打开.EXE 作为 Windows “运行...”?

[英]How to open .EXE with Javascript/XPCOM as Windows “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).我有一个内部网 web 应用程序,它需要运行一些外部应用程序,如 Word、记事本和其他特定应用程序……我的代码允许使用 IE (ActiveX) 和 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.当我使用整个路径(如“C:\windows\notepad.exe”)时,我可以在两种浏览器中运行,但问题是:Microsoft Word(2003、2007、2010.. .),并且本地路径总是不同的,但是如果我在 Windows 中使用“运行...”选项,我只能键入“winword.exe”并加载 MS Word,除了它的版本。 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.如果我在 IE 中只将文件名传递给 ActiveX,我可以调用 MS Word,但在 Firefox 中,使用 XPCOM,我不是。 So, my question is: Is there any way to make the XPCOM code run MS Word just with it's relative path (filename)?所以,我的问题是:有什么方法可以让 XPCOM 代码仅使用它的相对路径(文件名)运行 MS Word? 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.我相信您的问题在于 IE 直接与 Windows 一起使用,而 Firefox 旨在跨平台。 Assuming you only want this to work on Windows, you could execute the command prompt假设您只希望它在 Windows 上工作,您可以执行命令提示符

    C:\Windows\System32\cmd.exe

and pass it an argument like并传递给它一个参数

    start winword.exe

Then it will perform in the same manner as Run.然后它将以与 Run 相同的方式执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM