IE调用客户端程序实例

参考MSDN http://msdn.microsoft.com/en-us/library/aa767914.aspx 怎样为一个程序注册一个 URL 协议
核心代码为注册表

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Alert]
@="AlterProtocol"
"URL Protocol"="C:\\Alert.exe"

[HKEY_CLASSES_ROOT\Alert\DefaultIcon]
@="C:\\Alert.exe,1"

[HKEY_CLASSES_ROOT\Alert\shell]

[HKEY_CLASSES_ROOT\Alert\shell\open]

[HKEY_CLASSES_ROOT\Alert\shell\open\command]
@="\"C:\\Alert.exe\" \"%1\""

到这里已经为 Alert.exe 注册了一个叫  Alert 的协议。在IE地址栏输入 alert://Hello 便可启动客户端的Alert.exe 程序

看Alert.exe的代码先:

namespace Alert
{
    class Program
    {
        static string ProcessInput(string s)
        {
            // TODO Verify and validate the input 
            // string as appropriate for your application.
            return s;
        }

        static void Main(string[] args)
        {
            Console.WriteLine("客户端程序调用");
            Console.WriteLine("Alert.exe 参数如下:\r\n");
            Console.WriteLine("Raw command-line: \n\t" + Environment.CommandLine);

            Console.WriteLine("\n\n参数:\n");
            foreach (string s in args)
            {
                Console.WriteLine("\t" + ProcessInput(s));
            }
            Console.ReadKey();

        }
    }
}

如果您开启了360网页防火墙:首次运行 会出现这样的提示:
360 
放行即可。
如果您的C盘没有Alert.exe:
3601    3602
运行的效果:
3604

附件下载: Alert.rar

posted @ 2010-05-11 15:08  码尔代夫iimax  阅读(1219)  评论(0编辑  收藏  举报