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..
Loading
Kirtan PatelPosted Jan 14, 2010, 12:44 AM
friend, please check "Do you like this answer" check box if my answer helps you :-)
private void btnKillCMD_Click(object sender, EventArgs e)
{
foreach (Process p in Process.GetProcesses())
{
if (p.ProcessName == "cmd")
{
p.Kill();
}
}
}