c#写一个自动安装包带7z自动解压释放安装

博客分类: csharp 阅读次数: comments

c#写一个自动安装包带7z自动解压释放安装

设置安装包参数和信息

        public string strCompanyNameEnglish = "liberxue";
        public string strProductNameEnglish = "liberxue";
        public string strServiceNameEnglish = "liberxue";
        public string strCompanyURL = "http://www.liberxue.com";
        private System.Collections.Specialized.StringCollection folderCol;
        private static ZipClass zipClass = new ZipClass();  //压缩工具类
        private static UnZipClass unZipC = new UnZipClass();  //解压缩类
                lblDoing.Text = "正在向系统注册程序...";
                lblLoadingDoing.Size = new Size(lblLoadingDoing.Size.Width + 85, lblLoadingDoing.Size.Height);
                Application.DoEvents();
                RegistryKey hm = Registry.LocalMachine;
                hm = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\windows\\CurrentVersion\\Uninstall", true);
                RegistryKey psd = hm.CreateSubKey(strProductNameEnglish);
                psd.SetValue("DisplayIcon", strInstallationPath + "\\Edujoy_clientH5.exe");
                psd.SetValue("DisplayName", Application.ProductName);
                psd.SetValue("DisplayVersion", Application.ProductVersion);
                psd.SetValue("Publisher", Application.CompanyName);
                psd.SetValue("UninstallString", strInstallationPath + "\\UnInstall.exe");
                psd.SetValue("HelpLink", strCompanyURL);
                psd.SetValue("HelpTelephone", "4008009800");
                psd.SetValue("EstimatedSize", "45MB");
                psd.SetValue("URLInfoAbout", strCompanyURL);

快捷方式和开始菜单栏写入

  if (bStartMenuLink)
                    {
                        lblDoing.Text = "正在创建开始菜单快捷方式 ...";
                        lblLoadingDoing.Size = new Size(lblLoadingDoing.Size.Width + 92, lblLoadingDoing.Size.Height);
                        Application.DoEvents();
                        if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\" + Application.ProductName + "\\"))
                        {
                            Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\" + Application.ProductName + "\\");
                        }
                        sc.Save(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\" + Application.ProductName + "\\" + Application.ProductName + ".lnk");
                        sc = new Installation.Common.Shortcut();
                        sc.Path = strInstallationPath + "\\EdujoyLogin.exe";
                        sc.Arguments = "";
                        sc.WorkingDirectory = strInstallationPath;
                        sc.Description = "";
                        sc.Save(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\" + Application.ProductName + "\\卸载.lnk");
                    }
                }

安装完成善后工作

 lblDoing.Text = "正在清理安装时释放的临时文件...";
                lblLoadingDoing.Size = new Size(lblLoadingDoing.Size.Width + 95, lblLoadingDoing.Size.Height);
                Application.DoEvents();
            REDELETE:
                try
                {
                    File.Delete(strInstallationPath + "\\Debug.zip");
                   // File.Delete("liberxue.InstallationLog");
                }
                catch 
                {
                    Thread.Sleep(10);
                    Application.DoEvents();
                    goto REDELETE;
                }

关于写入注册列表和控制面板卸载的注册列表注释下 DisplayName 名称 DisplayVersion 显示版本 InstallDate 安装日期 InstallSource 安装源 Language 语言 ModifyPath 修改命令 NoModify 禁止修改 NoRepair 禁止修复 Publisher 发布者 UninstallString 卸载命令 Version 版本 VersionMajor 主要版本 VersionMinor 次要版本 HelpLink 帮助链接 WindowsInstaller 通过Windows Install安装 SystemComponent 系统组件 EstimatedSize 大小 LogFile 日志文件 LogMode 记录模式 URLInfoAbout 关于链接 Comments 注释 HelpTelephone 技术支持电话 InstallLocation 安装目标地址 Readme Readme文档所在地 URLUpdateInfo 升级信息链接 NoRemove 禁止删除(耍贱…) Contact 联系方式 DisplayIcon 图标 QuietUninstallString 安静卸载模式命令