在vs2008下制做c/s程序安装包(中包含第三方控件注册)

 

 

 

 

 

                                         图1

 图1中IWshRuntimeLibray是在“引用”-->“添加引用”,选择“COM”标签页中,选择“Windows Script Host Object Model”

                               图2

 

                                                 图3

 

                                                    图4

 

 

                                         图5

 

                        图6

 

                                                       图7

 

Install项目-->JLInstaller文件代码:

 

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using Library.Application;
using System.Windows.Forms;
using System.IO;


namespace Install
{
    [RunInstaller(true)]
    public partial class JLInstaller : Installer
    {
        public JLInstaller()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 安装
        /// </summary>
        /// <param name="stateSaver"></param>
        public override void Install(System.Collections.IDictionary stateSaver)
        {
            base.Install(stateSaver);
            InstallApplication();
        }

        /// <summary>
        /// 安装后
        /// </summary>
        /// <param name="savedState"></param>
        protected override void OnAfterInstall(System.Collections.IDictionary savedState)
        {
            base.OnAfterInstall(savedState);
        }

        /// <summary>
        /// 卸载
        /// </summary>
        /// <param name="savedState"></param>
        public override void Uninstall(System.Collections.IDictionary savedState)
        {
            string _TargetDir = this.Context.Parameters["TargetDir"];
            Logging.WriterInstallLog(_TargetDir, "开始执行卸载!");
            try
            {
                //删除快捷
                CreatingShortcuts.DeleteDesktopShortcuts();
                CreatingShortcuts.DeleteProgramsShortcuts();
            }
            catch
            {
                Logging.WriterInstallLog(_TargetDir, "执行卸载失败!");
            }

            base.Uninstall(savedState);
        }

        /// <summary>
        /// 卸载后
        /// </summary>
        /// <param name="savedState"></param>
        protected override void OnAfterUninstall(System.Collections.IDictionary savedState)
        {
            string _TargetDir = this.Context.Parameters["TargetDir"];
            try
            {
                //删除安装目录
                CreatingShortcuts.DeleteStallerDir(_TargetDir);
            }
            catch
            {
                Logging.WriterInstallLog(_TargetDir, "执行卸载成功!");
            }
            base.OnAfterUninstall(savedState);
        }

        /// <summary>
        /// 回滚
        /// </summary>
        /// <param name="savedState"></param>
        public override void Rollback(IDictionary savedState)
        {
            //删除快捷
            CreatingShortcuts.DeleteDesktopShortcuts();
            CreatingShortcuts.DeleteProgramsShortcuts();
            //string filePath = base.Context.Parameters["TargetDir"];
            //Directory.Delete(filePath, true);
            base.Rollback(savedState);
        }

        /// <summary>
        /// 安装流程
        /// </summary>
        private void InstallApplication()
        {
            string filePath = base.Context.Parameters["TargetDir"];
            Logging.WriterInstallLog(filePath, "--------------------------");
            Logging.WriterInstallLog(filePath, "开始安装现金流通管理系统");
            int num = 0;
            try
            {
                //第三方控件注册
                if (RegisterInstallInfo.RegisterAdd2Assembly(filePath))
                {
                    Logging.WriterInstallLog(filePath, "注册成功!");
                }
                else
                {
                    Logging.WriterInstallLog(filePath, "注册失败!");
                    num++;
                }
                //创建快捷方式
                if (CreatingShortcuts.CreatingProgramMenuFolder(filePath) && CreatingShortcuts.CreatingShortcut(filePath))
                {
                    Logging.WriterInstallLog(filePath, "成功创建快捷方式!");
                }
                else
                {
                    Logging.WriterInstallLog(filePath, "创建快捷方式失败!");
                    num++;
                }
                if (num != 0)
                {
                    throw new Exception("安装失败!");
                }
                else
                {
                    Logging.WriterInstallLog(filePath, "安装成功!");
                    Logging.WriterInstallLog(filePath, "-----------------------");
                }
            }
            catch (Exception exception)
            {
                Logging.WriterInstallLog(filePath, "安装失败!");
                Logging.WriterInstallLog(filePath, "-----------------------");
                Logging.WriterInstallLog(filePath, exception.ToString());
                Logging.WriterInstallLog(filePath, "------------------------");
                MessageBox.Show("安装失败,具体安装内容请查看安装日志InstallLogyyyymmdd.txt!");
                throw new Exception("安装失败,安装程序已经停止!");
            }
        }

       
    }
}

 

Library项目-->Application目录-->CreatingShortcuts文件代码:

using System;
using System.Collections.Generic;
using System.Text;
using IWshRuntimeLibrary;

namespace Library.Application
{
    public class CreatingShortcuts
    {
        /// <summary>
        /// 创建桌面快捷方式
        /// </summary>
        /// <param name="FilePath">程序安装路径</param>
        public static bool CreatingShortcut(string FilePath)
        {
            bool Result = false;
            try
            {
                WshShell shell = new WshShell();
                string FolderPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "//" + "系统.lnk";
                if (System.IO.File.Exists(FolderPath)) // 如果快捷方式已经存在,则删除
                {
                    System.IO.File.Delete(FolderPath);
                }
                IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(FolderPath);
                shortcut.TargetPath = FilePath + "WindowsFormsApplication2.exe";

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值