close cmd.exe in task manager from C# windows application
problem wiht cmd.exe
i have to terminate cmd.exe(from task manager process) from C# windows application. The cmd.exe is opened as i am running my example.bat file in background. but when i want to stop that running batch file i have to terminate cmd.exe in task manager.
so i wrote this code :
string processName = "cmd";
Process[] processes = Process.GetProcessesByName(processName);
try
{
foreach (Process process in processes)
{
process.Close();
}
}
catch (Exception ez)
{
MessageBox.Show(" No Cmd open");
}
but not working.... any one having solution????????
p.Kill(); is closing cmd.exe Excellent
but at same time its throwing exception : Acees is Denied..