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.
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.
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();
}
}
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