通过bat文件生成注册表文件
set exePath="D:\\TestApp.exe" set protocolName=TestApp echo Windows Registry Editor Version 5.00 >regist.reg echo [HKEY_CLASSES_ROOT\%protocolName%] >>regist.reg echo "URL Protocol"=%exePath% >>regist.reg echo @="%protocolName% Protocol" >>regist.reg echo [HKEY_CLASSES_ROOT\%protocolName%\DefaultIcon] >>regist.reg echo @=%exePath% >>regist.reg echo [HKEY_CLASSES_ROOT\%protocolName%\shell] >>regist.reg echo [HKEY_CLASSES_ROOT\%protocolName%\shell\open] >>regist.reg echo [HKEY_CLASSES_ROOT\%protocolName%\shell\open\command] >>regist.reg echo @=%exePath% %L >>regist.reg ::regedit /s ./regist.reg ::del /q regist.reg pause>nul运行生成的regist.reg,自动吧需要的信息写入到注册表
通过命令还方式启动,可以传入多个参数,在Unity中可以使用下面方式获取参数列表:
var args = = Environment.GetCommandLineArgs();通过网页启动,经测试,程序只能接收到一个参数,具体使用如下:
//参数: testapp://test_args //参数以在注册表中写入的名字+://开头 string arg = Environment.GetCommandLineArgs()[0]; //该参数是经过Url转义的,需要变成非转义形式才能使用 string usableUrg = Uri.UnescapeDataString(arg));