安装项目

 控件     

       //
            // trackBar1
            //
            this.trackBar1.Location = new System.Drawing.Point(12, 49);
            this.trackBar1.Minimum = 1;
            this.trackBar1.Name = "trackBar1";
            this.trackBar1.Size = new System.Drawing.Size(250, 45);
            this.trackBar1.TabIndex = 1;
            this.trackBar1.Value = 5;
            this.trackBar1.ValueChanged += new System.EventHandler(this.trackBar1_ValueChanged);
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(222, 12);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(58, 23);
            this.button1.TabIndex = 2;

 

            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.CanDragNoBorderForm_MouseUp);
            this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.CanDragNoBorderForm_MouseDown);
            this.MouseLeave += new System.EventHandler(this.CanDragNoBorderForm_MouseLeave);
            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.CanDragNoBorderForm_MouseMove);
            this.button1.Text = "关闭";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);

后台

 

public Form1()
        {
            InitializeComponent();
            this.Opacity = 0.5;     /// 透明度
        }

        private void trackBar1_ValueChanged(object sender, EventArgs e)
        {

            this.Opacity = (this.trackBar1.Value + 0.0) / 10;
        }
        private void button1_Click(object sender, EventArgs e)
        { this.Close(); }
        private void CanDragNoBorderForm_MouseDown(object sender, MouseEventArgs e)
        {
            this.isLButtonDown = true;
            this.mousePosition = e.Location;
        }
        private void CanDragNoBorderForm_MouseUp(object sender, MouseEventArgs e)
        {
            this.isLButtonDown = false;
        }
        private void CanDragNoBorderForm_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.isLButtonDown)
            {
                this.Location = new Point(this.Location.X + e.X - this.mousePosition.X, this.Location.Y + e.Y - this.mousePosition.Y);
            }
        }
        private void CanDragNoBorderForm_MouseLeave(object sender, EventArgs e)
        {
            this.isLButtonDown = false;
        }
        /// <summary>
        /// 鼠标左键是否按下
        /// </summary>

        private bool isLButtonDown = false;
        /// <summary>
        /// 鼠标在窗体上的位置
        /// </summary>
        private Point mousePosition = new Point(0, 0);

 

安装项目库

 

public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);
            string databaseServer = Context.Parameters["chk"].ToString();

            //MessageBox.Show(Environment.CurrentDirectory);
            //string path = Path.Combine(Environment.CurrentDirectory, "setup.exe");
            //MessageBox.Show(Application.StartupPath);
            //GetAppName();
            runExe(@"F:\setup\Setup1\Setup2\Debug\setup.exe");
            //这里操作添加数据库,只要执行创建数据库的脚本就可以了。


            //这个是测试在安装目录下添加接收到的用户填写的数据库信息
            //File.WriteAllText(Path.Combine(targetdir, "log.txt"), databaseServer + "/n/r" + userName + "/n/r" + userPass);
        }

        public void openPro(string appName)
        {
            try
            {
                Process proc = Process.Start(appName);
                if (proc != null)
                {
                    proc.WaitForExit(3000);
                    if (proc.HasExited)
                        MessageBox.Show(String.Format("外部程序 {0} 已经退出!", appName), appName,
                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    else
                    {
                        // 如果外部程序没有结束运行则强行终止之。
                        proc.Kill();
                        MessageBox.Show(String.Format("外部程序 {0} 被强行终止!", appName), appName,
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message, appName,
                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        public string GetAppName()
        {
            Process[] processes = Process.GetProcesses();
            string tmp = "";
            int i = 0;//调试时为了查找线程的个数
            foreach (Process pro in processes)
            {
                //MSI Title即为你的打包文件在运行时显示的标题
                //if (pro.ProcessName.ToLower() == "msiexec" && pro.MainWindowTitle == "Setup1")
                //{
                //    //这里在Vista下测试时因为要读写文件(由于Vista使用了UAC来增强安全性,
                //    //要求必须以管理员身份运行,而直接运行msi文件只能以普通权限来运行),
                //    //所以不让用户直接运行MSI文件,而要求必须从Setup.exe文件运行,
                //    //如果你不需要在Vista下使用则不用如此处理
                //    MessageBox.Show(pro.MainModule.FileName);
                //    return pro.MainModule.FileName;
                //    MessageBox.Show("Please run setup.exe", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //    throw new InstallException("run");
                //}
                if (pro.ProcessName.ToLower().IndexOf("setup")>0 && pro.MainWindowTitle == "Setup1")
                {//判断ProcessName是否是setup,并且其MainWindowTitle为你的安装文件的Title
                    tmp = tmp + pro.Id + "" + pro.ProcessName + Environment.NewLine;
                    tmp = tmp + " " + i.ToString() + "=" + pro.MainModule.FileName + Environment.NewLine;//pro.MainModule.FileName即为Setup的完整运行路径
                    tmp = tmp + " " + i.ToString() + "=" + pro.MainWindowTitle + Environment.NewLine;

                   
                }
                //MessageBox.Show(pro.MainModule.FileName);
            }
            return tmp;
        }

        public void runExe(string appName)
        {
            try
            {
                // 启动外部程序
                Process proc = Process.Start(appName);
                if (proc != null)
                {
                    // 监视进程退出
                    proc.EnableRaisingEvents = true;
                    // 指定退出事件方法
                    proc.Exited += new EventHandler(proc_Exited);
                }
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show("异常"+ex.Message, appName,
                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        /// <summary>
        /// 启动外部程序退出事件
        /// </summary>
        void proc_Exited(object sender, EventArgs e)
        {
            MessageBox.Show(String.Format("Exit外部程序 {0} 已经退出!", "appName"), "appName",
            MessageBoxButtons.OK, MessageBoxIcon.Information);
            Application.Exit();
        }

 

你可能感兴趣的:(安装)