Access running app instance

I know how to set a mutex to tell me if the app is already running when I try to start a new instance and to not let me start the second instance. But how would I have the already running instance come back up?

I’m running on Windows 7

Use the win32 api calls


Check the WFS for usage examples and/or premade functions.

Use SetWindowPos to change the z-order and push your app to the top for the declare

To know when to push your app to the front, you may set up your app to listen through IPCSocket.

When the second copy starts and finds out it is already running, it

  • closes its IPCSocket that was listening, and
  • connects,
  • warns the first app it needs to push to front, then
  • closes its IPCSocket and quits.

Because the second app closing the IPCSocket will generate an error, you then need in your first app to

  • Close IPCSocket
  • Listen
    So if again another copy was launched it can receive warning.

I use this to set my app window on top of every other one :

Declare Function SetWindowPos Lib “user32” (hwnd As integer, _
hWndInsertAfter As Integer, x As integer, y As integer, _
cx As integer, cy As integer, wFlags As integer) As integer
Const SWP_NOMOVE = 2
Const SWP_NOSIZE = 1

Dim R as integer
R = SetWindowPos( self.handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)[/code]