• WEB程序调用客户端程序


    最近一个项目中要点击WEB页面上的链接启动自己编写的程序,而且还要接收参数,google了1.5小时,终于初步试验通过了。

    尝试google了:web send message windows form, bs call cs program, custom protocol...多个关键字组合,发现这种技术叫

    registered URL protocol,在这篇文章里介绍得比较详细:

    http://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx

    1)首先写一个测试程序:

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    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("Alert.exe invoked with the following parameters.
    ");
          Console.WriteLine("Raw command-line: 
    	" + Environment.CommandLine);
    
          Console.WriteLine("
    
    Arguments:
    ");
          foreach (string s in args)
          {
            Console.WriteLine("	" + ProcessInput(s));
          }
          Console.WriteLine("
    Press any key to continue...");
          Console.ReadKey();
        }
      }
    }

    我把程序编译成edss.exe

    2)用notepad编辑一个文件,改名为edss.reg

    Windows Registry Editor Version 5.00

    [HKEY_CLASSES_ROOTEDSS]
    @="URL:EDSS Protocol"
    "URL Protocol"=""

    [HKEY_CLASSES_ROOTEDSSDefaultIcon]
    @=""D:\alert\edss.exe""

    [HKEY_CLASSES_ROOTEDSSshell]

    [HKEY_CLASSES_ROOTEDSSshellopen]

    [HKEY_CLASSES_ROOTEDSSshellopencommand]
    @=""d:\alert\edss.exe" "%1""

    运行edss.reg后,总是提示有些注册表项写入不成功,折腾了半天,看了http等协议的定义,最后终于发现是360在干扰。

    关闭360安全卫士,注册表终于写入成功了!

    原来是360安全卫士阻止最后一个注册表项的写入:

    [HKEY_CLASSES_ROOTEDSSshellopencommand]
    @=""d:\alert\edss.exe" "%1""

    3)在IE中输入edss://hello,ie浏览器弹击一个安全警告窗口,确认后就正常启动了我的应用程序

    4)在chrome中试了一下不成功,后来发现在chrome中不能直接输入edss://hello来启动,必须写一个html页面。

    马上编写了一行html页面:<a href='edss://hello'> start my windows program </a>

    chrome也可以启动我的windows程序了!

    其它浏览器以后再试。

  • 相关阅读:
    详解Java API之正则表达式
    ios UIWindow 错误使用导致无法接收motionEnded(摇一摇)函数
    ios NSTimer的强引用问题
    ionic 接触的第一个Hybrid项目
    iOS 小经验:UIAnimation空对象导致crash
    iOS GCD 必读推荐,有关于单例使用问题
    ios NSString 转 float的注意
    iOS UIViewController 和 nib 相关的3个方法
    ios delegate 使用注意 assign,weak
    ios 使用autolayout 后button 的frame 无法设置问题!
  • 原文地址:https://www.cnblogs.com/speeding/p/3764739.html
Copyright © 2020-2023  润新知