首页 > 解决方案 > 如何防止重命名应用程序的运行?

问题描述

使用此代码,我可以防止重复的应用程序运行代码中给出的名称。

但是在创建应用程序后,该应用程序的名称(exe)可以更改并在同一台机器上运行多次。

如何防止它运行?

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");
        }
    }
}```

标签: c#

解决方案


推荐阅读