开发者

Launch local executable from greasemonkey

开发者 https://www.devze.com 2023-02-28 05:11 出处:网络
Below is the code I am trying (plus a few variations), there is a dialog asking for my permission, but still errors out with

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

开发者_如何学Go
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?


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号