Registering an Application to a URL Protocol

To enable an application to handle a particular URL Protocol, you must add a new key, with the appropriate keys and values, to the registry in HKEY_CLASSES_ROOT.

The new registry key must match the protocol scheme that is being added. For instance, to add a "note:" protocol, the key added to HKEY_CLASSES_ROOT should be note. Under this new key, the Default string value should be the display name of the new protocol, and the URL Protocol string value should contain either protocol-specific information or an empty string. Also under the new key, a DefaultIcon key and a shell key should be added. The Default string value under the DefaultIcon key must be the file name to use as an icon for this new URL protocol.

Under the shell key, a key using a verb (such as open) should be added. A command key and a DDEEXEC key may also be added under the key using a verb. The values under the command and DDEEXEC keys are used to call the application.

The following example shows which registry values might be added to register a new application (Notepad.exe in this example) to handle the new URL protocol.


HKEY_CLASSES_ROOT
note
(Default) = "
URL:Note Protocol"
URL Protocol= ""
DefaultIcon
(Default) = "notepad.exe"
shell
open
command
(Default) = "C:/WINDOWS/notepad.exe" "%1"

By adding these settings to the registry, any attempts to navigate to URLs such as "note:C:/MyFile.txt" would attempt to launch Notepad to edit the file C:/MyFile.txt. However, because the URL Protocol handler passes the complete URL string to the application registered in the command, Notepad.exe would be called with the following unanticipated command line syntax:

C:/WINDOWS/notepad.exe "note:C:/MyFile.txt"
Normally, this argument format would be handled by the application that processes the request. However, because Notepad.exe cannot be changed, the protocol prefix must be trimmed from the filename before calling Notepad. The following shell command will trim the prefix from the input string, and pass the rest to Notepad.exe:

@FOR /F "tokens=1* delims=:" %%a IN ("%~1") DO start notepad.exe "%%b"
If the preceding text were saved into a batch file, C:/WINDOWS/Note.cmd for example, the following registry value would correctly launch Notepad.exe with the file specified in the URL string:


HKEY_CLASSES_ROOT
note
shell
open
command
(Default) = "C:/WINDOWS/note.cmd" "%1"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值