Below is the code I am trying (plus a few variations), there is a dialog asking for my permission, but still errors out with
开发者_如何学GoError: 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?
@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?.
精彩评论