1

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.

thiagoprzy
  • 411
  • 2
  • 8
  • 21

1 Answers1

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

Mike Cluck
  • 31,869
  • 13
  • 80
  • 91
  • 2
    Just in case of someone has the interest on it, I passed the argument like this: parameters = ["/c start " + path]; //path, in that case, is 'winword.exe' – thiagoprzy May 31 '11 at 13:02
  • to be more explicit see here http://stackoverflow.com/questions/6472435/running-exe-in-firefox-why-do-i-get-an-error – Rebol Tutorial Jun 25 '11 at 16:14
  • 1
    Please note that, theoretically, Windows could be installed in a directory that is different than `C:\Windows`. – Fyodor Soikin Nov 26 '12 at 13:15
  • @Fyodor Soikin True, as a note to future users of @Mike C's technique here - use `%WINDIR%` instead. *i.e.* `%WINDIR%\System32\cmd.exe`. That way you will always have the right path. – Tersosauros Mar 27 '16 at 09:00