using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Windows.Forms;
using Microsoft.Win32;



namespace US.Browser.Service
{
    [RunInstaller(true)]
    public partial class ProjectInstaller : System.Configuration.Install.Installer
    {
        public ProjectInstaller()
        {
            InitializeComponent();
            //UKJOpen();//设置开机自动启动云浏览器
        }


        /// <summary>
        /// 设置开机启动
        /// </summary>
        //public void UKJOpen()
        //{
        //    //获取程序执行路径..
        //    string USTP = Application.ExecutablePath;//获取文件安装的路径
        //    RegistryKey _UZC = Registry.LocalMachine;//打开注册表
        //    RegistryKey _UZR = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");//打开开机启动的文件夹
        //    try
        //    {
        //        _UZC.SetValue("YDIE", USTP);//设置开机启动
        //        _UZC.Close();//关闭注册表
        //    }
        //    catch (Exception e)
        //    {
        //        MessageBox.Show("无法设置开机启动");
        //    }
        //}


        //安装之后
        protected override void OnAfterInstall(IDictionary savedState)
        {
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
            p.Start();
            p.StandardInput.WriteLine("sc stop USservice");
            p.StandardInput.WriteLine("sc config USservice type= interact type= own");
            p.StandardInput.WriteLine("sc start USservice");
            //p.WaitForExit(10);
            //p.StandardInput.WriteLine("exit");
            p.Close();
        }

        //卸载之前
        protected override void OnBeforeUninstall(IDictionary savedState)
        {
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
            p.Start();
            p.StandardInput.WriteLine("sc stop USservice");
            p.StandardInput.WriteLine("exit");
            p.Close();
        }
    }
}
