c# - 如何防止重命名应用程序的运行?
问题描述
使用此代码,我可以防止重复的应用程序运行代码中给出的名称。
但是在创建应用程序后,该应用程序的名称(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");
}
}
}```
解决方案
推荐阅读
- java - 在类路径资源 Mongobee 中定义名称为“mongoTemplate”的 bean 创建错误
- fonts - 中文 PDF 字体 STSong-Light 不适用于 Jasper Report
- ibm-mq - IBM MQ 消息复制到新队列
- reactjs - React redux thunk 如何获得一个更新的 reducer 值?
- python - 在 django celery 的上下文中使用函数列表
- linux - 接受来自 write 命令的消息的安全风险
- javascript - newsapi 不起作用?访问从源“null”获取...控制台中的错误
- oauth - OAuth2 授予类型客户端凭据 - 是否允许使用 GET 方法
- java - 在 Tomcat 中获取和保存应用程序范围变量
- php - 如何使用php显示oracle表