📌  相关文章
📜  如何使用 c# 代码示例关闭系统中的另一个应用程序

📅  最后修改于: 2022-03-11 14:49:21.361000             🧑  作者: Mango

代码示例2
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.*/
              
                 }
            
        }