private async void btnUnInstall_Click(object sender, EventArgs e)
        {
            _IsServiceUninstalling = true;
            LogInstallServiceString("Удаление службы.");
            btnUnInstall.Enabled = false;
            try
            {
                await Task.Factory.StartNew(() =>
                {
                    MuServiceInstaller muServiceInstaller = new MuServiceInstaller(this.tbInstallationpath.Text);
                    muServiceInstaller.Uninstall();
                });

                _isServiceUninstallComplete = true;
                LogInstallServiceString("Успешное удаление службы.");

                MessageBox.Show("Удаление MagicUpdater завершено.", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Application.Exit();
            }
            catch (Exception ex)
            {
                LogInstallServiceString(ex);
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                _IsServiceUninstalling = false;
                btnUnInstall.Enabled   = true;
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            if (args != null &&
                args.Length == 2 &&
                args[0] == "restart" &&
                !string.IsNullOrEmpty(args[1]) &&
                File.Exists(args[1]))
            {
                MuServiceInstaller muServiceInstaller = new MuServiceInstaller(args[1]);
                muServiceInstaller.Restart();
                return;
            }

            if (args != null &&
                args.Length == 2 &&
                args[0] == "uninstallService" &&
                !string.IsNullOrEmpty(args[1]) &&
                File.Exists(args[1]))
            {
                MuServiceInstaller muServiceInstaller = new MuServiceInstaller(args[1]);
                muServiceInstaller.UnInstallService(args[1]);
                return;
            }

            bool createdNew = true;

            using (Mutex mutex = new Mutex(true, Application.ProductName, out createdNew))
            {
                if (createdNew)
                {
                    AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new StartForm());
                }
                else
                {
                    Process current = Process.GetCurrentProcess();
                    foreach (Process process in Process.GetProcessesByName(current.ProcessName))
                    {
                        if (process.Id != current.Id)
                        {
                            break;
                        }
                    }
                }
            }
        }
Exemple #3
0
        private async void btnInstall_Click(object sender, EventArgs e)
        {
            btnInstall.Enabled     = false;
            _isServiceInstalling   = true;
            btnInstall.Enabled     = false;
            btnPrevousStep.Enabled = false;
            LogString("Установка службы.");

            try
            {
                bool res = false;
                await Task.Factory.StartNew(() =>
                {
                    MuServiceInstaller muServiceInstaller = new MuServiceInstaller(tbInstallationpath.Text);
                    res = muServiceInstaller.Install();
                });

                if (res)
                {
                    btnNextStep.Enabled       = true;
                    _isServiceInstallComplete = true;
                    LogString("Успешная установка службы.");
                }
                else
                {
                    LogString("Ошибка установки службы.");
                }
            }
            catch (Exception ex)
            {
                btnInstall.Enabled = true;
                LogString(ex);
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnInstall.Enabled = true;
            }
            finally
            {
                btnPrevousStep.Enabled = true;
                _isServiceInstalling   = false;
            }
        }
Exemple #4
0
 public StartForm()
 {
     InitializeComponent();
     btnUninstall.Enabled = MuServiceInstaller.IsServiceInstalled();
 }