0

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?

Clemens
  • 123,504
  • 12
  • 155
  • 268
JuanDYB
  • 590
  • 3
  • 9
  • 23
  • That's weird, as you are not accessing _modules_ of the other process. Which call exactly generates this exception? – PMF Sep 19 '22 at 07:02
  • The documentation of Process.MainModule states that this Exception may happen. So accessing that property counts as loading the module. Interesting [Read](https://stackoverflow.com/questions/9501771/how-to-avoid-a-win32-exception-when-accessing-process-mainmodule-filename-in-c) with some options. – Ralf Sep 19 '22 at 07:10

0 Answers0