Search code examples
c#windowssystemexe

Can (Close) send a ctrl-C (Php cli.exe) to an application on Windows


static Process procphp;
static void runPhpCommand()
    {
        string cPath = @"php";
        string cParams = "-S localhost:80";
        string filename = Path.Combine(cPath, "php.exe");
        procphp = System.Diagnostics.Process.Start(filename, cParams);
    }

This code Working. How to close this Process

more code or explanations what exactly is not working

   procphp.CloseMainWindow();
   procphp.Close();

procphp.CloseMainWindow();

procphp.Close();

Support Without parameter


Solution

  • Dear all, I found out.

            try
            {
                Process[] processes = Process.GetProcessesByName("php");
                foreach (var process in processes)
                {
                    MessageBox.Show(process.ToString());
                    process.Kill();
                }
            }
            catch
            {
                MessageBox.Show("No");
            }