I am working on a c# project. From my application i have to close another application (Both are my own applications). Can i get the instance of first application in the second?
4 Answers
you have to get all the process in the process array so that we will get which process is going on
Process []GetPArry = Process.GetProcesses();
foreach(Process testProcess in GetPArry)
{
string ProcessName = testProcess .ProcessName;
ProcessName = ProcessName .ToLower();
if (ProcessName.CompareTo("winword") == 0)
testProcess.Kill();
}
here winword is the another process or you can say application running whom we are going to kill
-
1Can be a good idea to exit the loop when the correct process is found.– jgauffinSep 22, 2010 at 13:11
-
A modern day version in C# would look like this:
var processArray = Process.GetProcesses();
var process = processArray.FirstOrDefault(p => p.ProcessName == "AcroRd32");
process?.Kill();
this can be done by using namedpipes
1- Use NamedPipe to send some event to close the second instance.
100% Working my Example Process is Notepad. i want to close/kill
Process[] myProcList = Process.GetProcessesByName("notepad");
foreach (Process Target in myProcList)
{
Target.Kill();
}