Detect if an application is running

From ISXKB

(Difference between revisions)
Jump to: navigation, search
(See also)
Current revision (18:21, 11 November 2007) (view source)
(spelling)
 
(5 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 Mutex ==
+
== Checking for a mutex ==
-
It is possible to use
+
Every GUI application should create a mutex on startup. [[Application considerations]] explains this in a bit more detail and points out additional considerations.
-
function CheckForMutexes(Mutexes: String): Boolean;
+
Inno Setup can easily check the application's mutex if the 'AppMutex' directive is added to the script's [Setup] section.
 +
<pre>
 +
[Setup]
 +
AppMutex=MyMutexName
 +
</pre>
 +
This is the recommended way.
-
to check for a specified mutex, to see which mutexes are created by an application you can use [http://www.microsoft.com/technet/sysinternals/ProcessesAndThreads/ProcessExplorer.mspx ProcessExplorer].
+
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.
-
== Checking for a Class Name ==
+
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 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 Name ==
+
== 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 30: Line 44:
== See also ==
== See also ==
*[[Application considerations]]
*[[Application considerations]]
 +
*[[Application considerations#Application is running|Application is running]] in the article [[Application considerations]]
*[[Files in use extension]]
*[[Files in use extension]]
 +
 +
== External links ==
 +
*[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://msdn2.microsoft.com/en-us/library/ms684266.aspx Mutex objects] on MSDN
[[Category:Applications]]
[[Category:Applications]]
-
[[Category:Process Functions]]
+
[[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

External links

Personal tools
Ads: