How do I make a button that can kill/end a process?

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1536 Views - Last Post: 22 August 2009 - 05:29 AM Rate Topic: -----

#1 SexSquirrel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 19-August 09

How do I make a button that can kill/end a process?

Post icon  Posted 19 August 2009 - 08:42 PM

Hello everyone, I just started learning C# about 3 days ago and I need you help! I have a very simple question that I'm sure you all know the answer to it and here it is. How do I make a button that would kill/end a process? Btw, I already know how to make a button, I just need help on how to make the button kill/end a process. Thank you all in advanced. :)

Is This A Good Question/Topic? 0
  • +

Replies To: How do I make a button that can kill/end a process?

#2 oQMr FoxQo  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 123
  • Joined: 16-August 09

Re: How do I make a button that can kill/end a process?

Posted 19 August 2009 - 08:48 PM

View PostSexSquirrel, on 19 Aug, 2009 - 07:42 PM, said:

Hello everyone, I just started learning C# about 3 days ago and I need you help! I have a very simple question that I'm sure you all know the answer to it and here it is. How do I make a button that would kill/end a process? Btw, I already know how to make a button, I just need help on how to make the button kill/end a process. Thank you all in advanced. :)
you can post
this is a C++ forum the forum of C# is here
you can post it there
Was This Post Helpful? 0
  • +
  • -

#3 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5226
  • View blog
  • Posts: 26,997
  • Joined: 10-May 07

Re: How do I make a button that can kill/end a process?

Posted 19 August 2009 - 08:54 PM

View PostoQMr FoxQo, on 19 Aug, 2009 - 09:48 PM, said:

this is a C++ forum the forum of C# is here
you can post it there

No need to duplicate post, I moved it for you both :)
Was This Post Helpful? 0
  • +
  • -

#4 SexSquirrel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 19-August 09

Re: How do I make a button that can kill/end a process?

Posted 19 August 2009 - 09:42 PM

Thank you for moving my thread :) and sorry for posting in wrong section :(

This post has been edited by SexSquirrel: 19 August 2009 - 09:43 PM

Was This Post Helpful? 0
  • +
  • -

#5 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5226
  • View blog
  • Posts: 26,997
  • Joined: 10-May 07

Re: How do I make a button that can kill/end a process?

Posted 19 August 2009 - 09:47 PM

No worries :)
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How do I make a button that can kill/end a process?

Posted 19 August 2009 - 10:23 PM

Here's a snippet showing how to kill a process. Then you just need to call it in the buttons click event :)
Was This Post Helpful? 0
  • +
  • -

#7 SexSquirrel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 19-August 09

Re: How do I make a button that can kill/end a process?

Posted 20 August 2009 - 10:59 PM

Alright, thanks I'll try that. :)
Was This Post Helpful? 0
  • +
  • -

#8 SexSquirrel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 19-August 09

Re: How do I make a button that can kill/end a process?

Posted 20 August 2009 - 11:59 PM

I have put the code into my program but when I try debugging it, it says that I have build errors.. If I post my code here can someone correct my mistakes? I can't post it now because I'm on my psp..
Was This Post Helpful? 0
  • +
  • -

#9 SexSquirrel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 19-August 09

Re: How do I make a button that can kill/end a process?

Posted 21 August 2009 - 03:47 PM

Here is my code hopefully someone can correct my mistake. :)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace My_First_Program
{
	public partial class Notepad1 : Form
	{
		public Notepad1()
		{
			InitializeComponent();
		}

		private void Button_Click_Event2_Close(object sender, EventArgs e)
		{

		}

		private void Button_Click_Event_1_Start(object sender, EventArgs e)
		{
			public bool FindAndKillProcess(string name)
			{
				foreach (Process clsProcess in Process.GetProcesses()) {
			{
				if (clsProcess.ProcessName.StartsWith(notepad))
				{
					clsProcess.Kill(notepad);
					return true;
				}
			}
			return false;
		}
	}
}

Was This Post Helpful? 0
  • +
  • -

#10 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How do I make a button that can kill/end a process?

Posted 21 August 2009 - 03:48 PM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#11 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6048
  • View blog
  • Posts: 23,473
  • Joined: 23-August 08

Re: How do I make a button that can kill/end a process?

Posted 21 August 2009 - 04:31 PM

if (clsProcess.ProcessName.StartsWith(notepad))
{
    clsProcess.Kill(notepad);
    return true;
}



Do you maybe mean "notepad"? Or do you have a string variable named notepad?
Was This Post Helpful? 0
  • +
  • -

#12 SexSquirrel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 19-August 09

Re: How do I make a button that can kill/end a process?

Posted 21 August 2009 - 04:46 PM

Yeah I do have an error, when I try debugging, a message comes up saying I have "Build errors"
Was This Post Helpful? 0
  • +
  • -

#13 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6048
  • View blog
  • Posts: 23,473
  • Joined: 23-August 08

Re: How do I make a button that can kill/end a process?

Posted 21 August 2009 - 06:31 PM

Now, put on your thinking cap...

Ready?

OK...

How are we supposed to know what your errors are????

Don't you think that might be useful information to provide???
Was This Post Helpful? 0
  • +
  • -

#14 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1003
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: How do I make a button that can kill/end a process?

Posted 21 August 2009 - 06:51 PM

Look closely:
private void Button_Click_Event_1_Start(object sender, EventArgs e)
		{
			public bool FindAndKillProcess(string name)
			{
				foreach (Process clsProcess in Process.GetProcesses()) {
			{
				if (clsProcess.ProcessName.StartsWith(notepad))
				{
					clsProcess.Kill(notepad);
					return true;
				}
			}
			return false;
		}


You've got a function within a function.

Also, notepad isn't defined as a variable, so, like JackOfAllTrades stated, you intended for it to be a string.

I would heavily consider that, before even thinking about writing applications - You take a look at the very basics of C#. If you can cope with me and my runny nose + video tutorials, mine should cover the basics.. Starting here: http://www.youtube.c...h?v=nkbmvkBo6zA
Was This Post Helpful? 0
  • +
  • -

#15 SexSquirrel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 19-August 09

Re: How do I make a button that can kill/end a process?

Posted 22 August 2009 - 02:08 AM

Sounds good..I'll take a look. Oh and sorry for my noobish questions..(I just started less than a week ago :( and considering that, I guess I shouldn't be trying to write applications)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2