Hi,
I need to Close / Kill the already opened Main Winform application through C# coding, and will sopport all the operatingg system (Win 7 32 & 64 bit, Vista 32 & 64 Bit etc).
I already tried the below code but some times it didn't work in XP.
And rest OS this is not working. Please find below code:
Process thisProc = null;
string processName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
foreach (Process openedProcesses in Process.GetProcesses())
{
if (openedProcesses.ProcessName.Contains(processName))
{
thisProc = openedProcesses;
thisProc.CloseMainWindow();
thisProc.Kill();
}
}
Thanks in Adavance.
How to close/Kill the already opened Main winform in C#
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Prabhu RajaRank #861 · 2.6K reputationPosted Oct 9, 2011, 10:53 PM EDT
Also Try this one. (untested)
thisProc = openedProcesses;
thisProc.CloseMainWindow();
thisProc.Dispose();
thisProc.Kill();
thisProc.Close();
VulpesRank #55 · 29.2K reputationPosted Oct 10, 2011, 1:13 AM EDT