Skip to content Skip to sidebar Skip to footer

Running Exe In Firefox Why Do I Get An Error

I run this in Firefox, when clicking on link, Firefox says NS_ERROR_FILE_UNRECOGNIZED_PATH wheread I followed the instruction from here How to open .EXE with Javascript/XPCOM as Wi

Solution 1:

In javascript literals, a backslash indicates the beginning of an escape sequence. If you actually want to represent a backslash, you can escape it with a double backslash.

ie 'C:\\Windows\\System32\\cmd.exe /c start winword.exe'

http://www.javascriptkit.com/jsref/escapesequence.shtml

EDIT: From the comments on the correct answer from the post you linked, it looks like the way he got it working was:

only pass the path to runexe: javascript:RunExe('C:\Windows\System32\cmd.exe')

set the params equal to the command args: var parameters = ["/c start winword.exe"];

So this would work theoretically:

<html><head><script>functionRunExe(path) {
    try {            
        var ua = navigator.userAgent.toLowerCase();
        if (ua.indexOf("msie") != -1) {
            MyObject = newActiveXObject("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 = ["/c start winword.exe"];
            run.run(false, parameters, parameters.length);
        }
    } catch (ex) {
        alert(ex.toString());
    }
}
</script></head><body><ahref="#"onclick="javascript:RunExe('C:\\Windows\\System32\\cmd.exe');">Open Word</a></body>

Although clearly it would be better to pass in the params as an argument than hardcode them as I've done here (or pass them in as part of the path and parse them out)

Post a Comment for "Running Exe In Firefox Why Do I Get An Error"