OR if ((System.IO.Path.GetFileNameWithoutExtension(().Location)).Count() > 1) ().Kill() This works for any application (any name) and will become true if there is another instance running of the same application.Įdit: To fix your needs you can use either of these: if ((System.IO.Path.GetFileNameWithoutExtension(().Location)).Count() > 1) return įrom your Main method to quit the method. var exists = (System.IO.Path.GetFileNameWithoutExtension(().Location)).Count() > 1 Private static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow) Private static extern bool SetForegroundWindow(IntPtr hWnd) SetForegroundWindow(runningProcess.MainWindowHandle)
ShowWindow(runningProcess.MainWindowHandle, SW_SHOWMAXIMIZED) Var runningProcess = (from process in Process.GetProcesses()
Process currentProcess = Process.GetCurrentProcess() It has the nice additional feature of bringing the already running instance forward.ĮDIT: updated the code to determine the application title automatically. This will probably do just what you want.