Answers for "how to close another app in system with c#"

C#
0

how to close another app in system with c#

Process[] runningProcesses = Process.GetProcesses();
foreach (Process process in runningProcesses)
{
    // now check the modules of the process
    foreach (ProcessModule module in process.Modules)
    {
        if (module.FileName.Equals("MyProcess.exe"))
        {
            process.Kill();
        } else 
        {
         enter code here if process not found
        }
    }
}
Posted by: Guest on November-12-2020
0

how to close another app in system with c#

using System.Diagnostics;

public void CloseProccessOfAnotherApplication(string name)
        {
            
                if (string.IsNullOrWhiteSpace(name))
                {
                    iap.WriteLog("Process Name Was Null! Error. Please Pass A Process Name");
                    Environment.Exit(1);
                }
                Process[] mainAppProcessOrProcessesRunning = Process.GetProcessesByName(name);
                foreach(var p in mainAppProcessOrProcessesRunning)
                 {
                p.Kill();
                // or p.close(); 
                /*If you have permission issues then you have to capture each MainWindow using the proccess, focus that window, and do mainWindow.Exit(). 
                This may require using system32 automation to mimic the user. You may also have to pull each Modal attached to the main window and close those before hand.*/
              
                 }
            
        }
Posted by: Guest on February-26-2021

C# Answers by Framework

Browse Popular Code Answers by Language