devxlogo

Restrict Users to Launching Only One Instance of an Application

Restrict Users to Launching Only One Instance of an Application

Use this code to make sure that users can only launch one instance of an application.

static void Main() {	Process ThisProcess = Process.GetCurrentProcess();	Process [] AllProcesses = Process.GetProcessesByName(ThisProcess.ProcessName);	if (AllProcesses.Length > 1)	{		MessageBox.Show(ThisProcess.ProcessName + " is already running",ThisProcess.ProcessName, MessageBoxButtons.OK, MessageBoxIcon.Error);	}	else	{		Application.Run(new MainForm());	}}

devx-admin

Share the Post: