Code: CSharp
using System.Diagnostics; // For prcesss related information using System.Runtime.InteropServices; // For DLL importing
Code: CSharp
private const int SW_HIDE = 0;
Code: CSharp
[DllImport("User32")] private static extern int ShowWindow(int hwnd, int nCmdShow);
Code:
SW_HIDE 0 SW_SHOWNORMAL 1 SW_NORMAL 1 SW_SHOWMINIMIZED 2 SW_SHOWMAXIMIZED 3 SW_MAXIMIZE 3 SW_SHOWNOACTIVATE 4 SW_SHOW 5 SW_MINIMIZE 6 SW_SHOWMINNOACTIVE 7 SW_SHOWNA 8 SW_RESTORE 9 SW_SHOWDEFAULT 10 SW_FORCEMINIMIZE 11 SW_MAX 11
Process[] processRunning = Process.GetProcesses();
This will return array of all the processes. After this you can use foreach loop to iterate through each process in the array.
Code: CSharp
int hWnd; Process[] processRunning = Process.GetProcesses(); foreach (Process pr in processRunning) { if (pr.ProcessName == "notepad") { hWnd = pr.MainWindowHandle.ToInt32(); ShowWindow(hWnd, SW_HIDE); } }
Code: CSharp
pr.Kill();