栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > Unity3D

Unity制作安装程序并写入注册表

Unity3D 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Unity制作安装程序并写入注册表

exe 写入注册表
  • 前言
  • 将unity变成安装文件
  • 将exe 写入注册表
    • 在class root 里面
  • C# 代码实现
  • 将两个exe 结合起来

exe 注册进入注册表,其它程序可以调起。

前言

最近unity 发布exe 并且需要web 调用exe. 具体实施如下:


将unity变成安装文件

参考文档:
https://www.pianshen.com/article/20331986969/

将exe 写入注册表

参考文档:
http://www.uml.org.cn/net/201406202.asp
总结一下:

在class root 里面

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">点击启动
   

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/900253.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号