Horje
how to close another app in system with c# Code Example
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
        }
    }
}
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.*/
              
                 }
            
        }




Csharp

Related
c# array last element Code Example c# array last element Code Example
switch with lambda c# Code Example switch with lambda c# Code Example
unity how to find the smallest value out of 2 numbers Code Example unity how to find the smallest value out of 2 numbers Code Example
meaning of ??= in c# Code Example meaning of ??= in c# Code Example
conditional middleware .net core Code Example conditional middleware .net core Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8