I found this old C# code in one of my old backups. It was the case I wanted to hide an executable’s window and that executable has no relation with C# btw. It has a window that i want to hide with my C# code. Here you go.
[DllImport("User32")]
private static extern int ShowWindow(IntPtr handle, int nCmdShow);
private const int SW_HIDE = 0;
private void button1_Click(object sender, EventArgs e)
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "notepad.exe";
Process p = Process.Start(psi);
p.WaitForInputIdle() ; //Wait until app is running - if one doesn't wait here then there may be no main window to hide
ShowWindow(p.MainWindowHandle, SW_HIDE);
}