从greasemonkey启动本地可执行文件

ala*_*and 5 javascript greasemonkey local-files

下面是我正在尝试的代码(加上一些变体),有一个对话框要求我的许可,但仍然出错

错误:获取属性 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);
Run Code Online (Sandbox Code Playgroud)

这是不可能的吗?

ari*_*iel 8

@Jano 答案是正确的,但您仍然可以.bat使用自定义协议处理程序(例如myprotocol://parameters. 还在这里解释:How to run local program (exe) via Chrome via HTML/javascript

将此键添加到您的注册表中:

HKEY_CLASSES_ROOT
   myprotocol
      (Default) = "URL:Test Protocol"
      URL Protocol = ""
      shell
         open
            command
               (Default) = "d:\test.bat" "%1"
Run Code Online (Sandbox Code Playgroud)

并在 .bat 中捕获参数:

set param=%1
echo Parameter is "%param:~13,100%
Run Code Online (Sandbox Code Playgroud)

Where:~13,100裁剪参数 ( myprotocol://)的前 13 个字符

然后在你的脚本只是使用上的自定义协议的URL window.location$.ajax或分配给<a>href