Detect if an application is running
From ISXKB
(Links) |
Current revision (18:21, 11 November 2007) (view source) (spelling) |
||
(3 intermediate revisions not shown.) | |||
Line 1: | Line 1: | ||
There are many ways to do that, looking for a mutex, a class, a window or a runnnig exe. | There are many ways to do that, looking for a mutex, a class, a window or a runnnig exe. | ||
- | See also [http://www.jrsoftware.org/iskb.php?mutexsessions HOWTO: Detect instances running in any user session with AppMutex on Inno Setup Knowledge Base]. | + | See also [http://www.jrsoftware.org/iskb.php?mutexsessions HOWTO: Detect instances running in any user session with AppMutex on the Inno Setup Knowledge Base]. |
__TOC__ | __TOC__ | ||
- | == Checking for a | + | == 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. | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
<pre> | <pre> | ||
[Setup] | [Setup] | ||
AppMutex=MyMutexName | AppMutex=MyMutexName | ||
</pre> | </pre> | ||
+ | This is the recommended way. | ||
+ | |||
See the topic [[Application considerations#Application is running|Application is running]] in the article [[Application considerations]] and Inno Setup's help file for more info. | See the topic [[Application considerations#Application is running|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 | ||
+ | <pre> | ||
+ | function CheckForMutexes (Mutexes: String): Boolean; | ||
+ | </pre> | ||
+ | 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 [http://www.microsoft.com/technet/sysinternals/ProcessesAndThreads/ProcessExplorer.mspx ProcessExplorer]. | ||
- | == Checking for a | + | == Checking for a Window class name == |
It is possible to use | It is possible to use | ||
- | function FindWindowByClassName(const ClassName: String): Longint; | + | function FindWindowByClassName (const ClassName: String): Longint; |
- | and get window handle if found. It is possible to use this handle to send window messages. | + | and get a window handle if found. It is possible to use this handle to send window messages. |
- | == Checking for a Window | + | == Checking for a Window name == |
Instaed of class it is possible to find a window if an application looking for windowname. | Instaed of class it is possible to find a window if an application looking for windowname. | ||
- | function FindWindowByWindowName(const WindowName: String): Longint; | + | function FindWindowByWindowName (const WindowName: String): Longint; |
== Checking for a running executable file == | == Checking for a running executable file == | ||
Line 43: | Line 50: | ||
*[http://www.jrsoftware.org/iskb.php?mutexsessions Inno Setup Knowledge Base] Detect instances running in any user session with AppMutex | *[http://www.jrsoftware.org/iskb.php?mutexsessions Inno Setup Knowledge Base] Detect instances running in any user session with AppMutex | ||
*[http://www.microsoft.com/technet/sysinternals/ProcessesAndThreads/ProcessExplorer.mspx ProcessExplorer] for Windows | *[http://www.microsoft.com/technet/sysinternals/ProcessesAndThreads/ProcessExplorer.mspx ProcessExplorer] for Windows | ||
+ | *[http://msdn2.microsoft.com/en-us/library/ms684266.aspx Mutex objects] on MSDN | ||
[[Category:Applications]] | [[Category:Applications]] | ||
- | [[Category:Process | + | [[Category:Process functions]] |
Current revision
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
- Application considerations
- Application is running in the article Application considerations
- Files in use extension
External links
- Inno Setup Knowledge Base Detect instances running in any user session with AppMutex
- ProcessExplorer for Windows
- Mutex objects on MSDN