To prevent user from running multiple instances of my application, I am using this code:-
Process[] pArry = Process.GetProcesses();
int nCount = 0;
foreach (Process p in pArry)
{
string ProcessName = p.ProcessName;
ProcessName = ProcessName.ToLower();
if (ProcessName.CompareTo("myApp") == 0)
{
nCount++;
}
}
if (nCount > 1)
{
MessageBox.Show(AppAlreadyRunning,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
Process.GetCurrentProcess().Kill();
}
But As we know, Process Name changes if change the exe name. So If user changes "myApp.exe" to "UserApp.exe", This patch won't work! Is there any way out?
I am using C# in VS2010. Thanks!