Here is an example to allow software to run only once on a machine.
If the user tries to start the application again, there will ne a notification box and the program will exit.
[file] program.cs in visual studio
using System;
using System.Threading;
using System.Windows.Forms;namespace myapplicationnamespace
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
/// Only Once Instance Mode Mutex Variable and Remove IDE Error Message
#pragma warning disable IDE0052
private static Mutex mutex = null;
#pragma warning restore IDE0052
[STAThread]
static void Main()
{
//
// Only One Instance Mode
//
// One Instance Mode - Disable Warning Message on FailError
const string appName = "MyApplicationName";
#pragma warning disable IDE0018
bool createdNew;
#pragma warning restore IDE0018mutex = new Mutex(true, appName, out createdNew);
if (!createdNew)
{
// App is Running
MessageBox.Show("Only one instance allowed!");
return;
}//Default
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}