0

Guys how can I kill a process by its title name in c#. Say the title of Internet Explorer window is MSN | USA - Hotmail, Messenger...

I am making a small task manager like app that can kill an app with its title.

gb achilles
  • 21
  • 1
  • 3

2 Answers2

5

You can get all the IE processes, and then cycle through them, and check the windowtitle. Something like this:

System.Diagnostics.Process[] IEProcesses = System.Diagnostics.Process.GetProcessesByName("iexplore.exe");
        foreach (System.Diagnostics.Process CurrentProcess in IEProcesses)
        {
            if (CurrentProcess.MainWindowTitle.Contains("MSN | USA - Hotmail, Messenger"))
            {
                CurrentProcess.Kill();
            }
        }
Nicolai
  • 2,835
  • 7
  • 42
  • 52
  • Give full working C# sample please. (lot of time waste to search and not finding the right answer) –  Jun 28 '16 at 22:50
0

You need to research the EnumWindows P-Invoke function.

Start here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633497(v=vs.85).aspx

Then go here: http://pinvoke.net/default.aspx/user32.EnumWindows , and here: http://pinvoke.net/default.aspx/user32.GetWindowText

Finally here: Issue with EnumWindows

Community
  • 1
  • 1
Anders Marzi Tornblad
  • 18,896
  • 9
  • 51
  • 66