最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Launch local executable from greasemonkey - Stack Overflow

programmeradmin2浏览0评论

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

unsafeWindowscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); 

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

var process = unsafeWindow.Components.classes["@mozilla/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?

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

unsafeWindowscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); 

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

var process = unsafeWindow.Components.classes["@mozilla/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?

Share Improve this question asked Apr 24, 2011 at 21:18 alandaland 2,0142 gold badges29 silver badges44 bronze badges 1
  • I guess I should add that I'm currently testing this with FF 3.6.11. – aland Commented Apr 24, 2011 at 21:30
Add a ment  | 

2 Answers 2

Reset to default 10

@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
            mand
               (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)

  1. 暂无评论