RKK*_*KKC 11 windows registry uri protocols
我们有一个专为 google chrome 设计的应用程序,我们需要在其中添加一个指向网络文件共享的链接。不幸的是,file:// protocol出于安全目的,Chrome 拒绝了。我们想建立一个自定义协议来允许这个功能。
我认为这样做的一个好方法是调用资源管理器。以下是我们添加的注册表项:
[HKEY_CLASSES_ROOT\MyApp\DefaultIcon]
@="\"C:\\Windows\\explorer.exe\""
[HKEY_CLASSES_ROOT\MyApp\shell]
[HKEY_CLASSES_ROOT\MyApp\shell\open]
[HKEY_CLASSES_ROOT\MyApp\shell\open\command]
@="\" C:\\Windows\\explorer.exe\" \"%1\""
Run Code Online (Sandbox Code Playgroud)
目前,我们收到一个错误,指出协议无效。任何人都可以协助纠正这个问题吗?
非常感谢大家。
@沃尔夫拉姆施密德,
我刚刚使用 CMD 为您编写了一个解决方法:
REGEDIT4
[HKEY_CLASSES_ROOT\IntranetFileLauncher]
@="URL:IntranetFileLauncher Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\IntranetFileLauncher\DefaultIcon]
@="\"C:\\Windows\\explorer.exe\""
[HKEY_CLASSES_ROOT\IntranetFileLauncher\shell]
[HKEY_CLASSES_ROOT\IntranetFileLauncher\shell\open]
[HKEY_CLASSES_ROOT\IntranetFileLauncher\shell\open\command]
@="cmd /c set url=\"%1\" & call set url=%%url:intranetfilelauncher:=%% & call start explorer file:%%url%%"
Run Code Online (Sandbox Code Playgroud)
上面的代码基本上和你的一样,除了在最后一行它使用 cmd.exe 打开一个文件/文件夹的命令。在伪代码中:打开 commandpromt,将给定的文件路径作为变量 'url' 传递,通过剥离协议标识符来更改变量 'url',最后使用剥离的文件路径打开资源管理器
我希望这会有所帮助。
我在 Windows 8 / Firefox 上得到了以下内容。
此 MSDN 文章中描述了注册自定义协议的正确方法。
遗憾的是,您不能将其直接应用于 Windows Explorer。如果这样做,您会发现 Explorer 开始生成副本,直到您的记忆力或耐心耗尽为止,您必须注销才能停止它。原因是处理协议的应用程序通过了包括协议规范在内的整个链接。即,如果您有链接
localdir:D:\somefolder,
由此产生的调用将不会
explorer D:\somefolder,
但
explorer localdir:D:\somefolder.
这样做显然是为了让同一个应用程序可以处理多个协议。但是 Explorer 并没有意识到它是用来处理请求的,而是重新开始解析过程,从而引发恶性循环。
为了解决这个问题,你调用一个简单的帮助应用程序,从参数中删除协议规范,然后用清理过的 string 调用 Explorer。
例如,我创建了一个基本的 Java 类Stripper。
import java.io.IOException;
public class Stripper {
public static void main(String[] args) {
String stripped = args[0].substring("localdir:".length());
try {
Runtime.getRuntime().exec("C:\\Windows\\explorer.exe "+stripped);
}
catch (IOException e) { /* error handling */ }
}
}
Run Code Online (Sandbox Code Playgroud)
以下是一个 .reg 文件,将所需的键添加到注册表中。这假设 Stripper 位于折叠中D:\Stripper。
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\localdir]
@="URL: localdir Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\localdir\shell]
[HKEY_CLASSES_ROOT\localdir\shell\open]
[HKEY_CLASSES_ROOT\localdir\shell\open\command]
@="cmd /c \"cd /d d:\\Stripper & java Stripper %1\""
Run Code Online (Sandbox Code Playgroud)
该命令调用命令行解释器,告诉它首先切换到包含我们帮助程序的目录,然后调用 JRE 来执行它。这有点尴尬,但它有效。
对于本机 .exe 文件,command密钥可能如下所示:
[HKEY_CLASSES_ROOT\localdir\shell\open\command]
@="<somepath>Stripper.exe %1"
Run Code Online (Sandbox Code Playgroud)
这是一个快速而不肮脏的解决方案,您显然希望添加检查和平衡以及可能更多的机制,但一般方法看起来可行。
| 归档时间: |
|
| 查看次数: |
4042 次 |
| 最近记录: |