Question

I Need to close a process containing the word "SoundCloud" I tried this but wont work it does show the messagebox with the full name but won't close the app the error system.indexoutofRangeException

 private void getprocess()
    {
        StringBuilder sb = new StringBuilder();
        richTextBox1.Clear();
        int i = 1;
        foreach (Process p in Process.GetProcesses("."))
        {
            try
            {
                if (p.MainWindowTitle.Length > 0)
                {

                    if (p.MainWindowTitle.Contains("SoundCloud"))
                    {
                        timer1.Stop();
                        timer1.Enabled = false;
                        MessageBox.Show("Close "+p.MainWindowTitle.ToString());
                        Process[] proc =      Process.GetProcessesByName(p.MainWindowTitle.ToString());
                        proc[0].Kill();

                    }
                    richTextBox1.AppendText("\n"+i.ToString()+" ). " + p.MainWindowTitle.ToString());
                    i++;

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Was it helpful?

Solution

Just omit the GetProcesssByName part and call p.Kill(). This will kill any process with "SoundCloud" in the main window title.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top