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();
}
}
}
源代碼下載地址:點擊打開鏈接
