最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Launch local executable from greasemonkey - Stack Overflow

matteradmin3PV0评论

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

Post a comment

comment list (0)

  1. No comments so far