none
How to prevent the running of rename application RRS feed

  • Question

  • With this code I can prevent duplicate application of the name given in the code from running.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace Demo
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                this.Text = "Demo";
                int ac = System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Count();
                if (ac > 1)
                {
                    MessageBox.Show("Application Already Running");
                    this.Close();
                }
            }

            private void button1_Click(object sender, EventArgs e)
            {
                MessageBox.Show("Hello World");
            }
        }
    }

    But after the application is created, the name of that application (exe) can be changed and run multiple times in the same machine.

    How to prevent it from running ?
    Saturday, December 7, 2019 11:09 AM

Answers

All replies