Is there a way to kill a process automatically by filtering its name?

I have a process in my Task Manager, which is end-able, but keeps starting up again.

No Anti Virus has found this ad-ware virus yet, and I'm starting to think the only way to stop it from opening is to filter out its name in a program.

This is a very brief example of what I want

If process.XXX Alive = True;
      {
          Get process.XXX.PID;
          PID.End();
      }

Please ask me for any additional information.

Edit: Changed 'id' to 'pid'

2 answers

  • answered 2018-05-16 06:16 Harout

    // Sub adware with the name of the process
    // Do not include .exe in the process name
    Process p[] = Process.GetProcessesByName("adware");
    
    foreach(Process pr in p) pr.Kill();
    

  • answered 2018-05-16 08:21 Ben

    Internally Task Manager uses the Windows Management API. From the command line you can kill processes by name, using the built-in wmic windows management console program.

    For example, this will kill all instances of notepad:

    wmic process where "name like '%notepad%'" call terminate
    

    It can do other things too:

    wmic process where "name like '%notepad%'" get executablepath
    

    Then you can find that file and delete it.

    Note: To kill processes not owned by you, you must use an elevated command prompt.

    Note 2: You don't say what the process is, so there is a danger that I am helping you destroy your system without realising it. Before doing this, find out what the executable path and command line are, and investigate whether they are actually problem software.

    wmic process where "name like '%program%'" get executablepath,commandline