3

I trying to develop a Firefox Add-on to run an exe file via the context menu of the browser (or a VBScript file, or a CMD command). I tried these and had no results:

  • using signed jar files
  • using Flash (fscommand)
  • using JavaScript (ActivexObject)
  • using Firefox Add-on SDK (nsIProcess&ctypes)

I always had a very popular end which says "security issues do not allow this". Does anyone have an idea without a dead end?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
irohamca
  • 497
  • 3
  • 19
  • You can't execute any executables from any browser due to security issues but you can do it with HTA (HTML Application) with extension .hta So what kind of executable do you wich to launch ? – Hackoo May 26 '15 at 08:13
  • It can either be a vbscript or a bat file – irohamca May 26 '15 at 08:15
  • Also, HTA looks appropriate for IE, does it work with Firefox and Chrome. – irohamca May 26 '15 at 08:18
  • So i ask you again which program do you want to execute ? the path of this executable ? – Hackoo May 26 '15 at 08:26
  • In this case you should edit and post the source code of runExeScript.vbs – Hackoo May 26 '15 at 08:41
  • I have an add-on folder which is named 3cxClickToCall. Inside it there exist data, doc, lib, test folders. Inside data folder there is the file runExeScript.vbs. In the vbs file there is a line CreateObject("wscript.shell").run "mspaint.exe". Exact file that I want to run is C:\ProgramData\3CXPhone for Windows\PhoneApp\CallTriggerCmd.exe – irohamca May 26 '15 at 08:42
  • runExeScript.vbs opens mspaint automatically when double clicked, there is no problem about this, but I cannot trigger it from browser. – irohamca May 26 '15 at 08:43
  • Web browsers go to great lengths to prevent execution of random files out of security considerations. Please take a step back and describe the actual problem you're trying to solve instead of what you perceive as the solution. Do you have a web application from which you want to run that executable? Would a local standalone application (the HTA mentioned by @Hackoo) be an option? – Ansgar Wiechers May 26 '15 at 08:47
  • In fact, I try to create a firefox add on to make click to call for 3cx. I specifically need an add-on and need to run CallTriggerCmd.exe. I think there can be a way. – irohamca May 26 '15 at 08:51
  • I posted an answer to a similar question [here](http://stackoverflow.com/questions/16754621/how-can-i-open-an-external-app-from-firefox-addon-eg-default-text-editor/16756328#16756328) a while back that implements `nsILocalFile` and `nsIProcess`; Still works as far as I can tell. You will need access to `Cc` and `Ci` via `require("chrome")` if you plan on using it in the Addon SDK environment. – jongo45 May 27 '15 at 19:04

2 Answers2

2

I tried these and had no results: using Firefox Add-on SDK (nsIProcess&ctypes)

The addon sdk provides a way to launch processes out of the box: system/child_process

Firefox addons have the full power of the user account on the computer. If the user can start processes, so can a firefox addon.

So I do wonder what caused you to have "no results".

the8472
  • 40,999
  • 5
  • 70
  • 122
  • This is the cause of "no results" : TypeError: Components.classes is undefined. I used other modules like require("sdk/context-menu"), require('sdk/tabs'), but I could not define var {Cc, Ci} = require("chrome"). I tried all the variations but I see the same error. – irohamca Jun 02 '15 at 07:51
  • note that the module I linked doesn't require chrome privileges. although `require("chrome")` *should* work fine too. – the8472 Jun 02 '15 at 09:34
2

What ctypes did you try? I am launching exe's with ctypes in Windows with ShelExecuteEx, on Gtk (Unix) with g_app_info_launch_uris, and on OSX with popen open. I use these (instead of nsIProcess) because I needed it launched detached, meaning that the launching process is not waiting for response of close or etc from the launched process. On unix/linux/mac nsIProcess launching causes pid pollution. Meaning the pid of the launching process will be found on the launched process assets.

To launch with regular nsIProcess do so like this:

var procFinned = {
    observe: function (aSubject, aTopic, aData) {
      console.log('bash nsIProcess completed');
    }
};

var nsifile = new FileUtils.File('c:\blah\blah.exe');
var process = Cc['@mozilla.org/process/util;1'].createInstance(Ci.nsIProcess);
var args = [];
process.init(nsifile);
process.runAsync(args, args.length, procFinned);
Noitidart
  • 35,443
  • 37
  • 154
  • 323
  • I tried your code after your answer but It does not work, too. I use addon sdk_1.16. Have you got a complete example for nsIProcess. – irohamca Jun 05 '15 at 10:44