rajashanmugam

Hi

I'm having an application that generates some data and stores in excel and its shown to the user,when i close the application the excel which is generated by the application should close

so i use

Process[] local = Process.GetProcessesByName("excel");

int pcount;

pcount = local.Length;

for (int i = 0; i < pcount; i++)

{

local[ i ].Kill();

}

This works fine but it closes all the excel application which was not created by the current application.

i want to close the excel which is created by current application,it should not close other excel files

is there any one to solve my problem



Re: Visual C# Express Edition problem while Killing a process

jrboddie

If you are starting the process in your application, you should save the variable that is associated with it. Then use the variable to kill it.

Here is a simple example which can start an Excel process and kill (only) the one that was started.

Process myProcess;

private void button1_Click(object sender, EventArgs e)

{

myProcess = Process.Start("excel");

}

private void button2_Click(object sender, EventArgs e)

{

myProcess.Kill();

}