Detect if an application is running

From ISXKB

Jump to: navigation, search

There are many ways to do that, looking for a mutex, a class, a window or a runnnig exe.

See also HOWTO: Detect instances running in any user session with AppMutex on the Inno Setup Knowledge Base.


Contents


Checking for a mutex

Every GUI application should create a mutex on startup. Application considerations explains this in a bit more detail and points out additional considerations.

Inno Setup can easily check the application's mutex if the 'AppMutex' directive is added to the script's [Setup] section.

[Setup]
AppMutex=MyMutexName

This is the recommended way.

See the topic Application is running in the article Application considerations and Inno Setup's help file for more info. No further action is required in the script.

However, it is also possible to use

function CheckForMutexes (Mutexes: String): Boolean;

to check for a specified mutex from a [Code] section.

To examine which mutexes are created by an application that you haven't developed yourself you can use ProcessExplorer.

Checking for a Window class name

It is possible to use

function FindWindowByClassName (const ClassName: String): Longint; 

and get a window handle if found. It is possible to use this handle to send window messages.

Checking for a Window name

Instaed of class it is possible to find a window if an application looking for windowname.

function FindWindowByWindowName (const WindowName: String): Longint;

Checking for a running executable file

You can use PSVince to detect if an executable is currently running.

See also

External links

Personal tools
Ads: