Share via

Task Manager

MiPakTeh 1,476 Reputation points
2021-10-09T23:55:15.437+00:00

Hi All,
Using Button2 to delete program running at startup.However it can delete "Team Viewer" but can't delete "Team Viewer Service".

somebody can correct this code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Task_M
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            UpdateProcessList();
        }
        private void UpdateProcessList()

        {
            listBox1.Items.Clear();
            foreach (System.Diagnostics.Process p in

            System.Diagnostics.Process.GetProcesses())
            {
                listBox1.Items.Add(p.ProcessName + " - " + p.Id);
            }
            textBox1.Text = "Processes running: " +
            listBox1.Items.Count.ToString();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            UpdateProcessList();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            foreach (System.Diagnostics.Process p in
            System.Diagnostics.Process.GetProcesses())
            {
                string[] arr = listBox1.SelectedItem.ToString().Split('-');
                string sProcess = arr[0].Trim();
                int iId = Convert.ToInt32(arr[1].Trim());

                if (p.ProcessName == sProcess && p.Id == iId)
                {
                    p.Kill();
                }

            }

            UpdateProcessList();
        }
    }
}
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


Answer accepted by question author
  1. P a u l 10,766 Reputation points
    2021-10-10T00:14:04.09+00:00

    This might be because the TeamViewer service was started by the SYSTEM user, but the client was started by your user. Try going into the bin folder of your project, right clicking your .exe file, running as administrator & see if it kills the service.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.