15 Replies - 1180 Views - Last Post: 22 August 2009 - 05:29 AM
#1
How do I make a button that can kill/end a process?
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.
Replies To: How do I make a button that can kill/end a process?
#2
Re: How do I make a button that can kill/end a process?
Posted 19 August 2009 - 08:48 PM
SexSquirrel, 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. 
this is a C++ forum the forum of C# is here
you can post it there
#4
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
#5
Re: How do I make a button that can kill/end a process?
Posted 19 August 2009 - 09:47 PM
No worries
#7
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.
#8
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..
#9
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;
}
}
}
#10
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
#11
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?
#12
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"
#13
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???
Ready?
OK...
How are we supposed to know what your errors are????
Don't you think that might be useful information to provide???
#14
Re: How do I make a button that can kill/end a process?
Posted 21 August 2009 - 06:51 PM
Look closely:
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
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
#15
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)
|
|

New Topic/Question
Reply




MultiQuote





|