You need to use Platform Invoke:
http://msdn.microsoft.com/en-us/library/26thfadc.aspx[
^]
It's easier than it sounds (depending on the parameters you need to hand over) - at a minimum, it's just a case of adding an attribute to a method declaration:
[DllIport("User32")]
private static extern int SetForegroundWindow(IntPtr hwnd);
Uses the method SetForegroundWindow from the system DLL file "User32.dll"
You can then just call it in C#:
public static void SingleInstance(this Process thisProcess)
{
foreach (Process proc in Process.GetProcessesByName(thisProcess.ProcessName))
{
if (proc.Id != thisProcess.Id)
{
ShowWindow(proc.MainWindowHandle, SW_RESTORE);
SetForegroundWindow(proc.MainWindowHandle);
thisProcess.Kill();
}
}
}
[edit]Typo: SetForgrondWindow for SetForegroundWindow - OriginalGriff[/edit]