There is a code that should complete the process that was launched from the specified folder:

namespace newkill { class Program { static void Main() { } string path = @"C:\Users\" + Environment.UserName + @"\AppData\Roaming\WindowsW0W32\"; public static void KillProcesses(string path) { Process.GetProcesses() // получаем все процессы .Where(p => CheckIfProcessFileEquals(p, path)) // берем только те, в которых пути к файлу совпадают .ToList() .ForEach(p => p.Kill()); // убиваем каждый } private static bool CheckIfProcessFileEquals(Process process, string path) { try { return process.MainModule.FileName.Equals(path, StringComparison.InvariantCultureIgnoreCase); // сравниваем пути, инорим кейс } catch (Win32Exception) { return false; // если MainModule недоступен - скипаем } } } } 

The file was launched from this folder - C:\Users\" + Environment.UserName + @"\AppData\Roaming\WindowsW0W32\ but after the program execution the process is not killed. What could be wrong? Version .NET 3.5

  • one
    Actually, this code looks at the full path to the file (including the name), and not the folder in which this file is located. And besides, you do not call this function. - MihailPw
  • @ ASG17, i.e. I need to point like this: C: \ Users \ "+ Environment.UserName + @" \ AppData \ Roaming \ WindowsW0W32 \ file.exe? - Movie Trailers
  • @ ASG17, I specified it like this - C: \ Users \ "+ Environment.UserName + @" \ AppData \ Roaming \ WindowsW0W32 \ file.exe, but still the process is not killed. - Cinema Trailers
  • 2
    Naturally. You do not call a function (I already wrote this in the second sentence ) - MihailPw
  • one
    Rewrite to loop and podobezhit. - Qwertiy

1 answer 1

You have exactly what is written in Main :

 static void Main() { } 

Ie no-go-go .

Correct:

 static void Main() { var path = @"C:\Users\" + Environment.UserName + @"\AppData\Roaming\WindowsW0W32\file.exe"; KillProcesses(path); } 

I also recommend getting the path to AppData using Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) and using Path.Combine() to concatenate the file path:

 static void Main() { var path = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Roaming", "WindowsW0W32", "file.exe"); KillProcesses(path); } 
  • @ ASG17, now everything works exactly, thank you! - Movie Trailers