首页 > 编程语言 >web调用本地exe应用程序并传入参数

web调用本地exe应用程序并传入参数

时间:2022-12-04 01:44:22浏览次数:69  
标签:web exe Protocol string 应用程序 Micro Live 注册表

1、exe创建注册表
2、web启动exe,并传真userId
3、exe取得服务器授权sig
4、web取得推流地址: 'http://v.ju918.com/live/26185_21639.m3u8'

从网页中通过自定义URL Protocol调用本地程序,需要将协议写到注册表中。
浏览器在解析到自定义URL Protocol之后,寻找注册表,通过注册表启动相应的程序并传入参数。
协议里面需要记录本地程序的路径信息。

一、HTML调用方式如下:

<a href="Micro.Live://">WebExe,启动Exe应用程序</a

二、PC端注册表格式如下:

在开始菜单处,打开“运行”工具,或者按Win+R,在“运行”输入字母“regedit”,按回车键。这是打开注册表编辑器的命令。

然后注册表编辑器就出现在桌面了,在计算下面,大家可以进行各种设置。

HKEY_CLASSES_ROOT设置注册表Micro.Live
 


 

常用的注册三种编辑注册表的方式如下

方式一、注册表文件格式如下:

Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Micro.Live] "URL Protocol"="C:\\Micro.Live.exe" @="Micro.Live.Protocol" [HKEY_CLASSES_ROOT\Micro.Live\DefaultIcon] @="C:\\Micro.Live.exe,1" [HKEY_CLASSES_ROOT\Micro.Live\shell] [HKEY_CLASSES_ROOT\Micro.Live\shell\open] [HKEY_CLASSES_ROOT\Micro.Live\shell\open\command] @="\"C:\\Micro.Live.exe\"\"%1\""

复制到(txt)记事本,然后另存为Micro.Live.reg.reg文件,打开运行文件;

方式二、控制台程序(C#)如下:

1、配置文件(ProtocolInfo.xml)放到本地程序目录(Debug)

<?xml version="1.0" encoding="utf-8" ?> <ArrayOfProtocolInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/2001/XMLSchema-instance">   <ProtocolInfo ProtocolName="Micro.Live.Protocol" ProgramName="Micro.Live.exe" NodeName="Micro.Live" /> </ArrayOfProtocolInfo>
2、创建控制台应用程序  
try {     List<ProtocolInfo> protocalInfos = ProtocolInfo.GetProtocolInfo(string.Format("{0}\\ProtocolInfo.xml", Environment.CurrentDirectory));     if (protocalInfos == null || protocalInfos.Count == 0)         Console.WriteLine("未获取协议的配置信息!请确保配置文件 ProtocolInfo.xml 在当前目录下。");     string nodeName = protocalInfos[0].NodeName;     string programFullPath = string.Format("{0}\\{1}", Environment.CurrentDirectory, nodeName);       RegistryKey key = Registry.ClassesRoot;     string a = (string)key.GetValue(nodeName, true);     if (!key.Name.Contains(nodeName))     {         RegistryKey software = key.CreateSubKey(protocalInfos[0].NodeName);         software.SetValue("URL Protocol", programFullPath);         software.SetValue("", protocalInfos[0].ProtocolName);           RegistryKey softwareDefaultIcon = software.CreateSubKey("DefaultIcon");         softwareDefaultIcon.SetValue("", string.Format("{0},{1}", programFullPath, 1));           RegistryKey softwareShell = software.CreateSubKey("shell");         softwareShell = softwareShell.CreateSubKey("open");         softwareShell = softwareShell.CreateSubKey("command");         softwareShell.SetValue("", string.Format("\"{0}\" \"%{1}\"", programFullPath, 1));     } } catch(Exception ex) {     Console.Write(ex.Message); }

  3、如果当前用户没有管理员权限,写注册表会被拒。程序需要添加app.manifest文件

方式三、部署添加注册表(C#)如下:

注册表页面,各个节点的键值为:

键(Key) 名称(Name) 值(Value)
Micro.Live   Micro.Live.Protocol
Micro.Live URL Protocol C:\Micro.Live.exe
Micro.Live/DefaultIcon   C:\Micro.Live.exe,1
Micro.Live/shell    
Micro.Live/shell/open    
Micro.Live/shell/open/command   "C:\Micro.Live.exe""%1"

 

 右键 => New =>键 =>字符串值 => 属性窗口 => Name/Value

 

三、WPF 程序处理参数

static class Program {         /// <summary>         //应用程序的主入口点。         //</summary>         [STAThread]         static void Main(string[] args)         {             CustomApplication app = new CustomApplication();             app.Run();         } }   class CustomApplication : Application {         protected override void OnStartup(StartupEventArgs e)         {             base.OnStartup(e);             if (e.Args.Length > 0)             {                 MainWindow window = new MainWindow(e.Args);                 window.Show();             }             else             {                 MessageBox.Show("未传入参数!");                 Application.Current.Shutdown();             }         } }

 

源代码下载地址:点击打开链接

 

标签:web,exe,Protocol,string,应用程序,Micro,Live,注册表
From: https://www.cnblogs.com/webenh/p/16949283.html

相关文章

  • java 线程池中 execute 和 submit 方法的区别
    ThreadPoolExecutorUML类图execute方法定义publicinterfaceExecutor{voidexecute(Runnablecommand);}submit方法定义publicinterfaceExecutorServiceextends......
  • Springboot 使用 Async (内置线程池)执行异步任务(对比WebAsyncTask的使用)
    使用Async执行异步任务@SpringBootApplication@EnableAsyncpublicclassApplication{publicstaticvoidmain(String[]args){SpringApplication.run(Applicati......
  • Spring @WebFilter 注解定义过滤器
    @Slf4j@Order(1)@WebFilter(filterName="myFilter",urlPatterns={"/asyncResultGet/*"},initParams={@WebInitParam(name="author",value="Jaemon")})publicc......
  • WEB IDE Code Server 安装及使用
    概述Coder是VSCode的WebIDE,分CodeServer和Coder,CodeServer安装在服务器上,Coder是一个WEB版的VSCode,但目前多数的VSCode插件无法使用。VSCode:https://code.visua......
  • web项目的开发--第一天
    如何分析需求、如何设计、编码实现、测试。用ssm架构实现CRM项目代码编写。CRM项目:关键是养成好的编程思想和编程习惯。技术架构视图层(view):展示数据,跟用户交互。......
  • 聊聊Web项目中的权限设计
    一般的Web项目中都少不了登录这个环节,登录之后就需要跳转到首页,并且根据当前用户的信息,获取到对应的菜单信息,可以操作的方法信息等等。这个只是针对于操作权限,至于数......
  • web相关概念回顾和web服务器软件_概述
    web相关概念回顾:1.软件架构:1.C/S:客户端/服务器端2.B/S:浏览器/服务器2.资源分类1.静态资源:所有用户访问后,得到的结果都是一样的,称为静态资源,静态资源可以直接被......
  • H3C5.5模拟器轻松WEB配无线
    H3C5.5模拟器轻松WEB配无线本地虚拟网卡地址设置AC端配置:[AC]iphttpenable[AC]iphttpsenable#开启httphttps服务[AC]vlan100[AC-vlan100]qu[AC]intvlan100[AC-Vl......
  • webpack
    目录简介解密方式简介!function(allModule){functionuseModule(whichModule){allModule[whichModule].call(null,"helloworld!");}useMod......
  • CodeBlocks Tried to run compiler executable but failed!
    Q:Triedtoruncompilerexecutablebutfailed!A:下载安装MingGW64下载地址:https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/atte......