Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>try this... I use it to determine at startup if another process is already running with the same name as the exe I'm trying to start, and then just bring that one to foreground, (and to focus) if it is already running... You could modify it to take a process name and test for that specific name... This will tell you if there is a process running with a certain name, but not where that process was loaded from ... </p> <p>If there is a process running with the specified name, then if that process had an exposed accessible method that returns where it was loaded from, you could call that method on the running process, otherwise, I don't know.. </p> <p>But just out of curiosity, why do you care, unless they're different? And if they're different in some way, code to use that difference (whatever it is) to detect which is loaded. But if they're the same how can it matter which on-disk image was used to load it?</p> <pre><code> [DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport("user32.dll")] private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); [DllImport("user32.dll")] private static extern bool IsIconic(IntPtr hWnd); private const int SW_HIDE = 0; private const int SW_SHOWNORMAL = 1; private const int SW_SHOWMINIMIZED = 2; private const int SW_SHOWMAXIMIZED = 3; private const int SW_SHOWNOACTIVATE = 4; private const int SW_RESTORE = 9; private const int SW_SHOWDEFAULT = 10; private static bool IsAlreadyRunning() { // get all processes by Current Process name Process[] processes = Process.GetProcessesByName( Process.GetCurrentProcess().ProcessName); // if there is more than one process... if (processes.Length &gt; 1) { // if other process id is OUR process ID... // then the other process is at index 1 // otherwise other process is at index 0 int n = (processes[0].Id == Process.GetCurrentProcess().Id) ? 1 : 0; // get the window handle IntPtr hWnd = processes[n].MainWindowHandle; // if iconic, we need to restore the window if (IsIconic(hWnd)) ShowWindowAsync(hWnd, SW_RESTORE); // Bring it to the foreground SetForegroundWindow(hWnd); return true; } return false; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload