471,616 Members | 1,253 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,616 software developers and data experts.

End an outside process

I know I can use this code to start a process. Any aimilar way to end one?

System.Diagnostics.Process.Start("EcpKpScript_01.e xe");

Feb 5 '07 #1
4 10446
On Feb 5, 2:04 pm, Chris <C...@discussions.microsoft.comwrote:
I know I can use this code to start a process. Any aimilar way to end one?

System.Diagnostics.Process.Start("EcpKpScript_01.e xe");

Get the process instance to want to end and call:
System.Diagnostics.Process.Kill()
Feb 5 '07 #2
C# says it does not have a definition for kill. I recall using this in VB.
Are yousure this is good for C#?
"Jay Riggs" wrote:
On Feb 5, 2:04 pm, Chris <C...@discussions.microsoft.comwrote:
I know I can use this code to start a process. Any aimilar way to end one?

System.Diagnostics.Process.Start("EcpKpScript_01.e xe");


Get the process instance to want to end and call:
System.Diagnostics.Process.Kill()
Feb 6 '07 #3
On Feb 6, 5:00 am, Chris <C...@discussions.microsoft.comwrote:
C# says it does not have a definition for kill. I recall using this in VB.
Are yousure this is good for C#?

"Jay Riggs" wrote:
On Feb 5, 2:04 pm, Chris <C...@discussions.microsoft.comwrote:
I know I can use this code to start a process. Any aimilar way to end one?
System.Diagnostics.Process.Start("EcpKpScript_01.e xe");
Get the process instance to want to end and call:
System.Diagnostics.Process.Kill()- Hide quoted text -

- Show quoted text -

Chris, try the following --

using System.Diagnostics;

int _processID;

private void button1_Click(object sender, System.EventArgs e) {
Process p = Process.Start("EcpKpScript_01.exe");
_processID = p.Id;
}

private void button2_Click(object sender, System.EventArgs e) {
foreach (Process proc in Process.GetProcesses()) {
if (proc.Id == _processID) {
proc.Kill();
}
}
}

Click button1 to start your program and then Click button2 to kill
it. This works for a test program I tried. Test it for yours.

-Jay

Feb 6 '07 #4
Jay, thank you!! Worked great! Here is what I did after seeing your code:

int processID;
bool processRunning = false;

private void buttonRun_Click(object sender, EventArgs e)
{
// Here is where I call engineerings ECP Script program to run
// the script we created
//System.Diagnostics.Process.Start("EcpKpScript_01.e xe");
if (processRunning == false)
{
Process p = Process.Start("EcpKpScript_01.exe");
processID = p.Id;
processRunning = true;
// update status bar
toolStripStatusLabel2.Text = "ECP Script Started";
}
else
{
foreach (Process proc in Process.GetProcesses())
{
if (proc.Id == processID)
{
proc.Kill();
}
}
processRunning = false;
// update status bar
toolStripStatusLabel2.Text = "ECP Script Stopped";
}
}

"Jay Riggs" wrote:
On Feb 6, 5:00 am, Chris <C...@discussions.microsoft.comwrote:
C# says it does not have a definition for kill. I recall using this in VB.
Are yousure this is good for C#?

"Jay Riggs" wrote:
On Feb 5, 2:04 pm, Chris <C...@discussions.microsoft.comwrote:
I know I can use this code to start a process. Any aimilar way to end one?
System.Diagnostics.Process.Start("EcpKpScript_01.e xe");
Get the process instance to want to end and call:
System.Diagnostics.Process.Kill()- Hide quoted text -
- Show quoted text -


Chris, try the following --

using System.Diagnostics;

int _processID;

private void button1_Click(object sender, System.EventArgs e) {
Process p = Process.Start("EcpKpScript_01.exe");
_processID = p.Id;
}

private void button2_Click(object sender, System.EventArgs e) {
foreach (Process proc in Process.GetProcesses()) {
if (proc.Id == _processID) {
proc.Kill();
}
}
}

Click button1 to start your program and then Click button2 to kill
it. This works for a test program I tried. Test it for yours.

-Jay

Mar 20 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

20 posts views Thread by Mandy Memphis | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.