Hi,
here the sample code it will kill only the excel process which are created at run time of that application.
To Collect the excel process id's
Hashtable objhashProcess = new Hashtable();
Hashtable objHashProcess1 = new Hashtable();
protected void CheckExcelProcess(int call)
{
try
{
if (call == 1)
{
int iCount = 0;
Process[] ps = Process.GetProcesses();
foreach (Process p in ps)
{
if (p.ProcessName.ToLower().Equals("excel"))
{
objhashProcess.Add(p.Id, iCount);
iCount++;
}
}
}
else if (call == 2)
{
int icount = 0;
Process[] ps = Process.GetProcesses();
foreach (Process p in ps)
{
if (p.ProcessName.ToLower().Equals("excel"))
{
if (!objhashProcess.Contains(p.Id))
{
objHashProcess1.Add(p.Id, icount);
icount++;
}
}
}
}
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
}
Here to kill the process which are opened by the application:
protected void killProcess()
{
try
{
Process[] ps = Process.GetProcesses();
foreach (Process p in ps)
{
if (p.ProcessName.ToLower().Equals("excel"))
{
if (objHashProcess1.Contains(p.Id))
{
p.Kill();
}
}
}
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
}
Thanks..