以编程方式向mailto协议注册Windows程序 [英] Register Windows program with the mailto protocol programmatically

查看:288
本文介绍了以编程方式向mailto协议注册Windows程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何做,以便将mailto:链接注册到我的程序中?

然后我该如何在程序中处理该事件?

我从Google的快速搜索中发现的大多数解决方案都是手动执行此操作,但是如果我的程序用户单击设置为默认电子邮件客户端"之类的按钮,则需要为他们自动执行此操作. /p>

已删除对Delphi的引用,因为答案与您的语言无关.

解决方案

@ Dillie-O:您的回答使我朝了正确的方向(我应该期望这只是注册表更改),我明白了在职的.但是,我将其标记为答案,因为我将添加一些在处理此问题时发现的其他信息.

只要有某种方法可以修改Windows注册表设置,此问题的解决方案实际上与您使用哪种编程语言都没有关系.

最后,这是答案:

  • 要将程序与计算机上的所有用户的mailto协议相关联,请将HKEY_CLASSES_ROOT \ mailto \ shell \ open \ command的默认值更改为:
    "您程序的可执行文件"%1"
  • 将程序与当前用户 的mailto协议相关联>,将HKEY_CURRENT_USER \ Software \ Classes \ mailto \ shell \ open \ command更改为默认值:
    "您程序的可执行文件"%1"

%1将替换为整个mailto URL.例如,给定链接:

<a href="mailto:user@example.com">Email me</a>

将执行以下操作:
"您的程序的可执行文件""mailto:user@example.com"

更新(通过shellscape进行评论):
从Windows 8开始,此方法不再按预期工作. Win8会强制执行以下密钥:HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ Shell \ Associati‌ons \ URLAssociations \ MAILTO \ UserChoice所选应用程序的ProgID被散列且无法伪造.这是皇家的皮塔饼

How do I make it so mailto: links will be registered with my program?

How would I then handle that event in my program?

Most of the solutions I found from a quick Google search are how to do this manually, but I need to do this automatically for users of my program if they click a button, such as "set as default email client".

Edit:

Removed reference to Delphi, because the answer is independent of your language.

解决方案

@Dillie-O: Your answer put me in the right direction (I should have expected it to just be a registry change) and I got this working. But I'm going to mark this as the answer because I'm going to put some additional information that I found while working on this.

The solution to this question really doesn't matter what programming language you're using, as long as there's some way to modify Windows registry settings.

Finally, here's the answer:

  • To associate a program with the mailto protocol for all users on a computer, change the HKEY_CLASSES_ROOT\mailto\shell\open\command Default value to:
    "Your program's executable" "%1"
  • To associate a program with the mailto protocol for the current user, change the HKEY_CURRENT_USER\Software\Classes\mailto\shell\open\command Default value to:
    "Your program's executable" "%1"

The %1 will be replaced with the entire mailto URL. For example, given the link:

<a href="mailto:user@example.com">Email me</a>

The following will be executed:
"Your program's executable" "mailto:user@example.com"

Update (via comment by shellscape):
As of Windows 8, this method no longer works as expected. Win8 enforces the following key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associati‌​ons\URLAssociations\‌​MAILTO\UserChoice for which the ProgID of the selected app is hashed and can't be forged. It's a royal PITA

这篇关于以编程方式向mailto协议注册Windows程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆