At my application starting I'm checking if same application is running and if it's true I kill previous process.
I'm doing it with the following code. I have to check companyName and copyrigth to ensure that I'll kill only process of my company and not other processes that can have same name as my process.
var currentProcess = Process.GetCurrentProcess();
var foundProcess = Process.GetProcessesByName(currentProcess.ProcessName).ToList();
if(foundProcess.Any())
{
foundProcess = foundProcess.Where(p => p.Id != currentProcess.Id);
foundProcess = foundProcess.Where(p => p.MainModule.FileVersionInfo.CompanyName.Contains("CompanyName") || p.MainModule.FileVersionInfo.LegalCopyrigth.Contains("CompanyName"));
}
if(foundProcess.Any()){
foundProcess.ForEach(p => p.Kill());
}
My problem is that I have exception A 32 bit processes cannot access modules of 64 bit process
when a process running with the name that I'm searching for is found runnig at 64 bits.
It's neccesary to compile my application at 64 bits or there is another way to achive this?