firefox - How to open .EXE with JavascriptXPCOM as Windows "Run..."? - Stack Overflow

I have an intranet web application who needs to run some external applications, like Word, Notepad and

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/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
            exe.initWithPath(path);
            var run = window.Components.classes['@mozilla/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 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/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
            exe.initWithPath(path);
            var run = window.Components.classes['@mozilla/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.

Share Improve this question asked May 30, 2011 at 14:34 thiagoprzythiagoprzy 4212 gold badges8 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

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 mand 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745211403a4616861.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信