从greasemonkey启动本地可执行文件
下面是我正在尝试的代码(加上一些变体),有一个对话框请求我的许可,但仍然出错
错误:获取属性 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);
这是不可能的吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@Jano 答案是正确的,但您仍然可以使用自定义协议处理程序(例如
myprotocol://parameters
)调用.bat
文件。此处还进行了解释:如何在本地运行通过 HTML/javascript 通过 Chrome 运行程序 (exe)将此键添加到注册表中:
并在 .bat 内部捕获参数:
其中
:~13,100
裁剪参数的前 13 个字符(myprotocol://
)然后在您的脚本中只需使用
window.location
、$.ajax
上的自定义协议 URL 或分配给 < code> 的href
。@Jano answer is right, but you can still invoke the
.bat
file using a custom protocol handler such asmyprotocol://parameters
. Also explained here: How to run local program (exe) via Chrome via HTML/javascriptAdding this keys to your registry:
And inside the .bat to capture the parameter:
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>
'shref
.你不能。请参阅Greasemonkey 脚本是否具有 Chrome 权限?。
You can't. See Do Greasemonkey scripts have chrome privileges?.