Kill process by Title name (not process name).

Hi, i'm making a program that terminates other processes by there window title. I'm having dificulties getting a process list and then getting the titles of them all.
Note: I dont need the process name, cuz its not certain that it will always be the same.

The general idea of the program is, it looks through the procsess list and then checks a MySQL database to se if theres any rows there teling the program to kill anyone of thees processes. The rows contain the title name, cuz thay usaly never change when it comes to games and sutch.
I got the SQL part done and its working really good together with ODBC, but i havent figured the process thing out yet, and im having a hard time doing it.

If any one got a better idea on how to kill a special program/process, be free to tell me.
LVL 1
ellis-Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dsaboCommented:
Hello,
   I found something that may be usefull to you.

   You need to bind an extisting process and then kill it. Here is a little code

using System.Diagnostics;
------------------------------

To kill a process by process name:

Process[] myProcesses;
myProcesses = Process.GetProcessesByName("Notepad");
myProcesses[0].CloseMainWindow();

To kill a process by MainWindowsTitle name:
Process[] myProcesses;
myProcesses = Process.GetProcesses();
                  
foreach(Process p in myProcesses)
{
     string Name = p.MainWindowTitle.ToLower();
     
    if(Name.IndexOf("title") != -1)
        p.CloseMainWindow();
}

I hope this helps you.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ellis-Author Commented:
Great!!
changed p.CloseMainWindow(); to p.Kill(); so it really closed it without warning.

Else, it works like a charm.
thx
//ellis
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.