Search code examples
c#processfilenameskill-process

C# How can I kill a process with .exe changing name, unnamed window and cannot use PID because I need to use something that does not change?


For learning purposes and mere curiosity I have been trying somehow to kill a process with the characteristics explained above in the title:

1. The name of the file changes every time it is downloaded.

2. Window without a name.

(I can't use PID because I need something that doesn't change to make it automatic)

(The exe name always start with DaxSS-

Example names:

DaxSS-TSFGR

DaxSS-RFDUC

DaxSS-GFFRS

Is there a way to do that?


Solution

  • The downloaded exe name always start with DaxSS

    That's your ticket right there!

    string start = "DaxSS".ToUpper();
    Process P = Process.GetProcesses().Where((p) => p.ProcessName.ToUpper().StartsWith(start)).FirstOrDefault();            
    if (P != null)
    {
        P.Kill();
    }