- 前言
- 将unity变成安装文件
- 将exe 写入注册表
- 在class root 里面
- C# 代码实现
- 将两个exe 结合起来
exe 注册进入注册表,其它程序可以调起。 前言
最近unity 发布exe 并且需要web 调用exe. 具体实施如下:
将unity变成安装文件
参考文档:
https://www.pianshen.com/article/20331986969/
参考文档:
http://www.uml.org.cn/net/201406202.asp
总结一下:
1, key: URL Protocol value: 需要调用的exe 路径
2,创建 DefaultIcon 文件夹
写入: key : exeName value: exe路径,1
3,创建 "shell/open/command"文件夹
写入: key : exeName value: “exe路径,%1”
C# 代码实现 class Register
{
private string exeName = "MapEditor";
///
/// 创建一个test注册表项,下面包含OpenLog,和SaveLog两个子项
///
public void CreateRegistFile(string exePath)
{
exePath = string.Format("{0}\{1}.exe", exePath, exeName);
Console.WriteLine("exepath="+exePath);
//SOFTWARE在LocalMachine分支下
RegistryKey rootkey = Registry.ClassesRoot;
RegistryKey appKey = rootkey.CreateSubKey(exeName);
// RegistryKey subkey = appKey.CreateSubKey("Path");
//新建键值,当键值名称为空时,将被设置为默认值
//appKey.SetValue(null, "URL");
appKey.SetValue("URL Protocol", exePath);
RegistryKey defaultIcon= appKey.CreateSubKey("DefaultIcon");
string exeOnePath = string.Format("{0},1", exePath);
defaultIcon.SetValue(exeName, exeOnePath);
RegistryKey shellKey= appKey.CreateSubKey("shell");
RegistryKey openKey= shellKey.CreateSubKey("open");
RegistryKey cmdKey= openKey.CreateSubKey("command");
string valuePath = string.Format(""{0}" "%1"", exePath);
cmdKey.SetValue(null, valuePath);
cmdKey.Close();
appKey.Close();
}
}
class Program
{
static void Main(string[] args)
{
Register tmpRegister = new Register();
string str = System.Environment.CurrentDirectory;
tmpRegister.CreateRegistFile(str);
Console.ReadLine();
}
}
将两个exe 结合起来
1,制作unity 安装exe 的时候 将 第二个程序也制作成一个控制台程序 ,的名字放入下图中。
2,web 调用测试代码
...... "MapEditor://command">点击启动



