Use the method Process.GetProcessesByName()
to obtain an array of the active processes in the system that share the same process name.
Use the function ShowWindow()
windows API with the parameters Process.MainWindowHandle
which informs Handler of the main process window and SW_MINIMIZE
who informs ShowWindow()
that the window must be minimised.
using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApp9
{
public partial class Form1 : Form
{
private const int SW_MINIMIZE = 6;
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
private void Button1_Click(object sender, EventArgs e)
{
Process[] localByName = Process.GetProcessesByName("notepad");
foreach (var item in localByName)
{
ShowWindow(item.MainWindowHandle, SW_MINIMIZE);
}
}
public Form1()
{
InitializeComponent();
}
}
}
Thank you, Augusto Vasques
– Reibeiro