哎!资质愚钝啊,看了半天没看太明白,但思路是明白了 ,就是要在注册表上动手脚。 于是乎继续google 找到了 http://blogs.gotdotnet.com/noahc/archive/2006/10/19/register-a-custom-url-protocol-handler.aspx 不幸让我看明白了。
俺简单的说说俺的理解吧。
要实现这个功能笼共分3步。(我们注册一个xishui:// 这样的 protocol-handler,实现在网页中点击xishui://hello,就弹出一个对话框,上面显示“hello”)
1 按照如下结构建立注册表

其中 [xishui] 是建立在注册表的 [HKEY_CLASSES_ROOT] 主键下。
2 给相关的键赋值



大家注意到上面 command 项的值为 c:\test.exe "%1" ,这个"%1"是传递给test.exe的参数。如果我们点击xishui://hello这样的链接 那么%1的值就是“xishui://hello” 这个字符串。
到此我们改写程序生成test.exe了,我们的目标是弹出一个对话框,显示xishui://hello链接中的hello字样。 也就是说我们要用正则表达式来取出"xishui://hello" 中 “xishui://” 后面的部分
我们来写一个控制台程序
















让我把编译生成的test.exe 复制到c:\下
然后 我写了个test.html

然后我在浏览器中点这个链接 ,啥效果?你猜

哇咔咔 真的调用了我的test.exe,并且显示了hello !