Пример #1
0
        static void Main(string[] args)
        {
            bool removeStartupTask = false;
            bool killInstance      = false;
            bool restartInstance   = false;

            foreach (string arg in args)
            {
                if (arg.ToLower() == "--remove-startup-task")
                {
                    removeStartupTask = true;
                }
                else if (arg.ToLower() == "--kill-instance")
                {
                    killInstance = true;
                }
            }

            if (removeStartupTask)
            {
                AutoRun.RemoveStartupTask();
            }

            if (killInstance || restartInstance)
            {
                Process currentProcess = Process.GetCurrentProcess();

                Process[] otherProcesses = Process.GetProcessesByName(currentProcess.ProcessName);
                foreach (Process otherProcess in otherProcesses)
                {
                    if (otherProcess.Id != currentProcess.Id)
                    {
                        otherProcess.Kill();
                    }
                }

                Thread.Sleep(100);
            }

            if (removeStartupTask || killInstance)
            {
                return;
            }

            using (Mutex mutex = new Mutex(false, $"Global\\{instanceGuid}"))
            {
                if (!mutex.WaitOne(0, false))
                {
                    MessageBox.Show("Eve.TapToClick is already running.");
                    return;
                }

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());
            }
        }
Пример #2
0
        private void startupCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            // If the form isn't done loading, ignore change events.
            if (!initialized)
            {
                return;
            }

            AutoRun.RemoveStartupTask();

            // If we're checked, add the task.
            // Just a note: we use task scheduler here as opposed to the "Startup" folder
            // or the registry, because those solutions will cause UAC prompt on startup.
            if (startupCheckbox.Checked)
            {
                AutoRun.AddStartupTask();
            }
        }