One simple way to do it is to list the running processes on the system and
see if another instance of the same name, running from the same location
exists, with a different process id exists.
Process current = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName
(current.ProcessName);
//Loop through the running processes in with the same name
foreach (Process process in processes)
{
//Ignore the current process
if (process.Id != current.Id)
{
//Make sure that the process is running from the exe file.
if (Assembly.GetExecutingAssembly().Location.
Replace("/", "\\") == current.MainModule.FileName)
{
//Return the other process instance.
return true;
}
}
}
Brendan
"Gidi" wrote:
Hi,
I saw that someone asked that question here before, and i tried one of the
answer that was gaven (Bob's tricks and tiips), The suggestion there was
using the ImoprtDll and tried to import the user32.dll, when i tried to
import it to the refernces, the Visual Studio crashed.
So how can i force one copy of application (i'll be happy and thankful to
get an example).
Thanks,
Gidi.