Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to terminate exe file window in C#?

Status
Not open for further replies.

qingxing2005

Technical User
Sep 2, 2006
6
SE
Dear all,

I had one program, which was written by C, and there are some outputs printed in the console window. Therefore, once you run the exe file, it is required to close window by using any key.

However, I start one exe program by using Proc.Start(); But I don't know how to terminate the console window following. Since I have to run the program for hundreds times. In this case, if I don't close the window, it will be hundreds of windows filled with my PC!!!

Hopefully, you can give me some hints.

Thanks in advance,

Cordially,

L.M
 
This is a brute force process kill. If you can modify your C code to exit after it completes, that would be the way to go. If not, you can use this.

You may get an error about Performance Couters being disabled. To fix this, you must set a value in the regsitry.

This value is under

Computer -> HKEY_LOCAL_MACHINE -> SYSTEM -> CurrentControlSet -> Services -> PerfProc -> Performance

Change the key "Disable Performance Couters" from 1 to 0 and you should have no problems.


Here's the code to kill the process

-------------------------------------------------------

using System.Diagnostics;

private void KillProcess(string name)
{
Process[] allprocesses = Process.GetProcessesByName(name);

foreach (Process p in allprocesses)
{
p.Kill();
p.WaitForExit();
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top