Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch local executable from greasemonkey

Below is the code I am trying (plus a few variations), there is a dialog asking for my permission, but still errors out with

Error: Permission denied for to get property XPCComponents.classes

unsafeWindow.netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); 

var file = unsafeWindow.Components.classes["@mozilla.org/file/local;1"]
    .createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("d:\\test.bat");

var process = unsafeWindow.Components.classes["@mozilla.org/process/util;1"]
    .createInstance(Components.interfaces.nsIProcess);
process.init(file);

var args = ["argument1", "argument2"];
process.run(false, args, args.length);

Is this just going to be impossible?

like image 318
aland Avatar asked Apr 24 '11 21:04

aland


2 Answers

@Jano answer is right, but you can still invoke the .bat file using a custom protocol handler such as myprotocol://parameters. Also explained here: How to run local program (exe) via Chrome via HTML/javascript

Adding this keys to your registry:

HKEY_CLASSES_ROOT
   myprotocol
      (Default) = "URL:Test Protocol"
      URL Protocol = ""
      shell
         open
            command
               (Default) = "d:\test.bat" "%1"

And inside the .bat to capture the parameter:

set param=%1
echo Parameter is "%param:~13,100%

Where :~13,100 Crops the first 13 characters of the parameter (myprotocol://)

Then in your script just use the custom protocol URL on window.location, $.ajax or assign to an <a>'s href.

like image 100
ariel Avatar answered Oct 09 '22 09:10

ariel


You can't. See Do Greasemonkey scripts have chrome privileges?.

like image 44
Jano Avatar answered Oct 09 '22 11:10

Jano