Try something like this
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool SetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
public struct WINDOWPLACEMENT
{
public int length;
public int flags;
public int showCmd;
public POINTAPI ptMinPosition;
public POINTAPI ptMaxPosition;
public RECT rcNormalPosition;
}
public struct POINTAPI
{
public int x;
public int y;
}
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[STAThread]
public static void Main()
{
Process[] procesos = Process.GetProcessesByName("YourMainFormProcessName");
bool openProcess= false;
if (procesos.Length > 1)
{
foreach (Process proceso in procesos)
{
IntPtr wHandle = proceso.MainWindowHandle;
if (wHandle != IntPtr.Zero)
{
openProcess = true;
WINDOWPLACEMENT wp = new WINDOWPLACEMENT();
wp.showCmd = 3;
SetForegroundWindow(wHandle);
SetWindowPlacement(wHandle, ref wp);
}
}
}
if (openProcess == false)
{
Application.Run(new frmMain());
}
}